Haru
Haru

Reputation: 1381

Run ErrorDocument before Mod Rewrite in Htaccess

When I turn rewrite off a 404 goes correctly to Google (used just to test) like it is supposed to. When it is on it runs the rewrite first and totally ignores the ErrorDocument declaration. I can't understand why it is doing this.

Options +FollowSymlinks
ErrorDocument 404 http://www.google.com
<IfModule mod_rewrite.c>
RewriteEngine Off
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Upvotes: 0

Views: 298

Answers (2)

Haru
Haru

Reputation: 1381

I was able to resolve my issue using

if ( is_404() ) {
      wp_redirect( 'static.htm' );
      exit;
   }

to customize my 404 further.

Upvotes: 1

Ravi K Thapliyal
Ravi K Thapliyal

Reputation: 51721

Well, the below in your .htaccess is saying

RewriteCond %{REQUEST_FILENAME} !-f     # if not a file
RewriteCond %{REQUEST_FILENAME} !-d     # if not a directory
RewriteRule . /index.php [L]            # redirect to index.php

So, either remove these rules or turn the rewrite engine off.

EDIT :
Permalinks work by catching 404(s) because the link structure physically doesn't exist. ErrorDocument doesn't override this because it can still be used as something to fall back upon if mod_rewrite decides to ignore a 404. For example,

RewriteCond %{REQUEST_FILENAME} !-f     # if not a file
RewriteCond %{REQUEST_FILENAME} !-d     # if not a directory
RewriteCond %{REQUEST_URI} ^/wordpress/ # & points to wordpress
RewriteRule . /index.php [L]            # redirect to index.php

Now, a domain.com/wordpress/no-such-file.php would redirect to /index.php whereas domain.com/no-such-file.php would redirect you to Google (because of ErrorDocument).

Upvotes: 1

Related Questions