I use .htaccess to display my 404 page, while showing the requested URL in the browser instead of the actual 404 URL. To do so, I have this line in my .htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /404.php [L]
This works good whenever I go to a non-existent file (i.e. blalba.php).
The problem is: When I try to go to my main site dir (i.e. http://example.com/), I see the 404 page. When I directly go to my index file (i.e. http://example.com/index.php), everything works just fine.
How could I modify the .htaccess to not redirect my main dir?
So that, in fact, the main dir is excluded from the rewrite code above.
ANSWER:
See answer below and adding RewriteCond %{REQUEST_FILENAME} !-d solved the problem!
I’m pretty sure you just forgot to tell apache that it needs to “default” to index.php if nothing is precised in the url. Here’s how you do:
Other answer about 404
I’ve had the same problem a few days ago. It’s simple: assign the error document to 404.php. Whenever there’s a 404, the server makes an internal redirection so that it can craft properly the web page.
So here’s a sample of my vhost config:
With all that you should be able to create your own rewriterules with proper 404 “filtering”.
Hope this helps!