Index.php mystery
Created: Last updated:
Thanks but no thanks. I have just spend, read wasted, about an hour tracing a little mystery which turned out to be some funny stuff with the browser, in my case Firefox.
I was testing a new module that captures and analyzes requests to certain file types, like the well known index.php. I don't really support the index.php file on my systems but some people (aka hackers) think (for whatever reasons) to send requests to an /index.php URI anyway.
With the new module I will be able to log such goofy requests in a special log file but also simply redirect to the root, aka homepage. Nice try, dude! Here's your homepage.
Stripping an extension
Now, there might be other people who (for also whatever unknown reason) think they have to send a request with an html or htm extension, like /home.html, /contact.html or /about.html. I may even have such a page but without the html.
Because I want my application to be a smart system this should be handled in a certain smart way and not just return a 404 Not found error page. The new module will actually do that now.
It will simply redirect the request without the extension. The module strips the extension and sends a 301 Moved permanently redirect because the page never has and never will exist.
I don't care and test at this point if there even is a page with that name. The redirect will solve this riddle anyway. If there happens to be a page with that name all is great with 200 OK response and if not, well, they get the 40x error code and page.
So far so good.
I used my Firefox browser and send a /index.php request and expected to see my debug message to work on the task at hand. Instead I received my 40x error page and an even bigger surprise the URL in the browser showed an URL without the extension. As if it was redirected like any other page I described above.
Firefox stripped php extension
After a lot of swearing, head banging and other insults thrown at my monitor screens I came to the conclusion that Firefox must send my index.php request as only index, i.e. they strip the php extension.
Whatever request I send with Firefox worked like clockwork but only the index.php did not. I finally fired up another browser and sure enough I suddenly see my debug message as expected. Back to Firefox it did not work.
Now, I don't know why some application developers sometimes come up with some decisions, i.e. making decisions for the user. I cannot really tell if the developers behind Firefox for some weird reason decided to always submit requests to index.php without the extension or if there is some caching going on or if it is one of the Add-ons.
On another system Firefox did work like expected but just not on my primary system. So thanks but no thanks to the developers who decided to strip the php extension. You wasted a hour of my life.