smalpierre
New member
Ok, so I've been using the Slim MVC framework as a front controller for a long time. It basically has an .htaccess file so when the url "http://www.mysite.com/routeidentifier/querystringdata" is called, it redirects to /index.php and looks for a route to the controller, and calls the controller specified.
Now I'm building my own front controller to eliminate a dependency for one, and also because I want to store routes in the database instead of in index.php so when I have thousands of links, I don't have a huge file to process or look at.
Anyway - what I did, was grabbed the .htaccess file from the root directory, and copied it to a new site's base directory. Then I created an index.php file. It can be anything - all it has to contain for the purpose of this test is something like var_dump($_SERVER['REQUEST_URI']); to keep it simple.
On my laptop (wampserver on Windows) it works as I expect it to: It should take every request no matter what, and route it to index.php in the document root which right now just displays everything you typed after the TLD part of the url. Well technically it displays data type, data, and length since I'm var_dumping instead of echoing ...
So if you type http://mylaptop.com it will return:
string '/' (length=1)
If you type http://mylaptop.com/index.php it returns the same thing
If you type http://mylaptop.com/directory/that/doesnt/exist it will return:
string '/directory/that/doesnt/exist' (length=28)
Now - I have a single folder under document root called "folderexists" with an index.php file that contains nothing but "echo("This folder actually exists!");"
If you type http://mylaptop.com/folderexists it will return:
This folder actually exists!
So this works exactly as I would like it to ... Now to the problem!
On my linux box, (Debian 8, Apache running php-fpm and opcode caches) it doesn't work so well.
if you type http://myserver.com it will return:
string '/' (length=1)
If you type http://myserver.com/index.php it returns the same thing
If you type http://myserver.com/directory/that/doesnt/exist it will return:
404 File Not Found (with apache notification underneath)
I haven't tried it with the directory that exists yet ...
If on the other hand you type http://myserver.com/index.php/directory/or/file/that/doesnt/exist it will return
string '/index.php/directory/or/file/that/doesnt/exist' (length=46)
That's because the file actually exists - index.php - so it doesn't have to redirect.
So the redirect obviously isn't working right?
Then why if I type http://myserver.com/doesntexist.php it returns
file not found
Which is different than the Apache
404 File Not Found (with apache notification under it)
My question is how do I make my server respond like my laptop? Here's the .htaccess contents:
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
It should work, and on the exact server it's not workin on in my simple case, it works for Slim MVC???
Now I'm building my own front controller to eliminate a dependency for one, and also because I want to store routes in the database instead of in index.php so when I have thousands of links, I don't have a huge file to process or look at.
Anyway - what I did, was grabbed the .htaccess file from the root directory, and copied it to a new site's base directory. Then I created an index.php file. It can be anything - all it has to contain for the purpose of this test is something like var_dump($_SERVER['REQUEST_URI']); to keep it simple.
On my laptop (wampserver on Windows) it works as I expect it to: It should take every request no matter what, and route it to index.php in the document root which right now just displays everything you typed after the TLD part of the url. Well technically it displays data type, data, and length since I'm var_dumping instead of echoing ...
So if you type http://mylaptop.com it will return:
string '/' (length=1)
If you type http://mylaptop.com/index.php it returns the same thing
If you type http://mylaptop.com/directory/that/doesnt/exist it will return:
string '/directory/that/doesnt/exist' (length=28)
Now - I have a single folder under document root called "folderexists" with an index.php file that contains nothing but "echo("This folder actually exists!");"
If you type http://mylaptop.com/folderexists it will return:
This folder actually exists!
So this works exactly as I would like it to ... Now to the problem!
On my linux box, (Debian 8, Apache running php-fpm and opcode caches) it doesn't work so well.
if you type http://myserver.com it will return:
string '/' (length=1)
If you type http://myserver.com/index.php it returns the same thing
If you type http://myserver.com/directory/that/doesnt/exist it will return:
404 File Not Found (with apache notification underneath)
I haven't tried it with the directory that exists yet ...
If on the other hand you type http://myserver.com/index.php/directory/or/file/that/doesnt/exist it will return
string '/index.php/directory/or/file/that/doesnt/exist' (length=46)
That's because the file actually exists - index.php - so it doesn't have to redirect.
So the redirect obviously isn't working right?
Then why if I type http://myserver.com/doesntexist.php it returns
file not found
Which is different than the Apache
404 File Not Found (with apache notification under it)
My question is how do I make my server respond like my laptop? Here's the .htaccess contents:
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
It should work, and on the exact server it's not workin on in my simple case, it works for Slim MVC???