3

In Apache 2, is the ordering between ErrorDocument and mod_rewrite defined and predictable? I can't find anything in the documentation about this.

For example, if I have the following in a .htaccess file (stripped down from the standard Drupal .htaccess file)

ErrorDocument 404 /index.php <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !=/favicon.ico RewriteRule ^ index.php [L] </IfModule> 

which will handle a request for a /favicon.ico, the ErrorDocument or the RewriteRule? Will this always be the same, server-to-server, or can this vary based on how Apache is configured?

1 Answer 1

3

Yes it's defined. Mod_Rewrite only works on incoming requests, before Apache has actually looked for the resource. ErrorDocument functions at the level of forming the response (basically the last step).

A slightly oversimplified version of how Apache would work in this case:

  • Receive Request
  • Modify Request (mod_rewrite and possibly others)
  • Get resources specified
  • Send response (which would be ErrorDocument if the resource wasn't found)
3
  • So, with the directives above, a request for /favicon.ico would get ignored by the RewriteRule b/c the RewriteCond, but would get punted back to index.php anyway b/c the ErrorDocument? Commented May 18, 2012 at 15:11
  • A related question would then be, would a request for /some/bad/path get handled by index.html twice, once from the RewriteRule and then once from the ErrorDocument? Commented May 18, 2012 at 15:31
  • Yes to the favicon.ico getting punted by ErrorDocument. No, mod_rewrite doesn't handle requests, it only modifies the incoming request. In this case mod_rewrite would pickup the bad URL and rewrite it to the presumably good "index.php", which would be further processed as if the original request always was for "index.php". Commented May 18, 2012 at 15:52

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.