Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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]

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?

share|improve this question
up vote 3 down vote accepted

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)
share|improve this answer
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? – MPD May 18 '12 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? – MPD May 18 '12 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". – Chris S May 18 '12 at 15:52
Thanks. This makes sense now. – MPD May 18 '12 at 15:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.