WordPress 404 template overriding my .htaccess settings for 404 errors?
Everything is being routed through wordpress so when a request for something like /sub/no_file.html
and it doesn't exist, wordpress routes it through its index.php
because it satisfies both the !-f
and !-d
conditions (not an existing file and not an existing directory). It then decides that it can't find the resource for /sub/no_file.html
so it then displays its own 404 file.
If you want requests that go to /sub to bypass wordpress' routing so that if a file is requested in /sub/
that doesn't exist, /404.html
gets served, you can add this line right before RewriteRule . /index.php [L]
in your wordpress rules so that they look like this:
<IfModule mod_rewrite.c>RewriteEngine OnRewriteBase /RewriteRule ^index\.php$ - [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_URI} !^/?sub/RewriteRule . /index.php [L]</IfModule>
The default .htaccess-file will already support the behaviour you want;
# BEGIN WordPress<IfModule mod_rewrite.c>RewriteEngine OnRewriteBase /RewriteRule ^index\.php$ - [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L]</IfModule># END WordPress
The magic is in the lines that start with RewriteCond. They instruct Apache to apply the rule RewriteRule . /index.php [L] (which means "any URL will go to index.php"), only when the URL is not an existing file !-f or existing directory !-d.
So this should work by default. The Wordpress rewrite rules do not apply when you try to visit an already existing file.