What is the Apache directive order of precedence?

in apache, mod_rewrite, wordpress, wpmu

I am trying to implement some mod_rewrite RewriteRules using WordPressMU. I tried putting them in the Virtural Host file, but they did not appear to work. Since WPMU has a set of mod_rewrite RewriteRules in a .htaccess file, I wondered if the order of precedence was the problem. It seems that was indeed the cause. Here is the order of Apache configuration processing order of precedence that I found:

1. Apache configuration file is parsed top to bottom.
2. Included files are parsed right at their include location. In other words within the configuration file.
3. For directives which are called more than once, the last call overrides the previous calls.
4. For a directive called more than once in a directory tree, the lowest call in the directory tree takes precedence.
5. .htaccess directives take precedence over the main configuration file Directives.

So, it does seem that the .htaccess directives are overriding the Virtual Host file.

Thanks to this source for helping clear this up: http://data-based-systems.com/articles/papers/ApacheNotes.html

David April 6, 2011 at 2:08 pm

“Aliases and Redirects are processed in the order they appear in the configuration files, with the first match taking precedence”.
http://httpd.apache.org/docs/2.2/mod/mod_alias.html#order

For mod_rewrite the last match is processed.
SO,
Alias/Redirect – First match wins
RewriteRule – Last match wins

In addition,
Redirect over Alias
Alias before Directory container
Location containers run once before Alias, so Location will apply.

Comments on this entry are closed.

Previous post:

Next post: