apache2 gives 404 before rewrite apache2 gives 404 before rewrite apache apache

apache2 gives 404 before rewrite


This sounds like there may be 2 things happening here.

  1. Mod_rewrite doesn't appear to be loaded
  2. Multiviews is making it appear as if mod_rewrite is loaded

What Multiviews does, is part of mod_negotiation which tries to "guess" what the request is for if it is missing things like an extension. So with Multiviews turned on, if it sees a request for /vt and the file vt doesn't exist, it guesses and finds /vt.php and serves that, otherwise it doesn't nothing and returns a 404. This would make it appear as if the mod_rewrite rule is actually being applied. If mod_rewrite is actually turned on, then it would apply the rule even if mod_negotiation was turned on and the file was missing (which would result in a 404).

So 1. make sure that mod_rewrite is actually loaded. To do this, check your httpd.conf file and there should be a line that looks like this (uncommented):

LoadModule rewrite_module modules/mod_rewrite.so

Or you can try removing the <IfModule mod_rewrite.c> container, if you get a 500 server error, mod_rewrite isn't loaded.

Then 2. add this line in your htaccess file to turn off Multiviews:

Options -Multiviews


You can simply define "/" as the "404 error document" by appending the following line to your .htaccess file, so the visitors return to your homepage or index.php.

ErrorDocument 404 /

If you want them to be redirected to a specific page, simply use

ErrorDocument 404 /path/to/your/404/file.ext