.htaccess
ErrorDocument 404
No redirection when using rewrite rules. A 500 Internal Server Error occurs.
Without RewriteRule
, ErrorDocument
works normally.
My code
RewriteEngine On <IfModule mod_rewrite.c> RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /stores/ [NC,L] ErrorDocument 404 /404.html </IfModule>
The "problem" with this rule is that if you request a file that doesn't exist, and the file doesn't exist in the /subdirectory/ subdirectory, then it will cause an infinite rewrite loop (hence the 500 you see Internal Server Error) because it attempts the following rewrite:
You didn't actually specify what you were trying to achieve, but I'm assuming /stores is a "hidden" subdirectory and you intended to overwrite to the actual files in the /stores subdirectory. This is the only way such a rule will work with the ErrorDocument 404 directive defined in Apache.
Therefore, when rewriting to the /stores subdirectory, you need to first check whether the request will be mapped to an actual file before issuing the rewrite. This way, any request for a file that does not exist and is not mapped to the /stores subdirectory will be passed to the Apache-defined 404 ErrorDocument.
For example, try using the following code:
No need for
<IfModule>
container (but you put the RewriteEngine directive outside this container, which makes no sense).If the .htaccess file is located in the document root directory, the RewriteBase directive is not required.
Structurally, it is best to define ErrorDocument first.