The order of directives Location, DirectoryIndex,and those in .htaccess

Knowing the order(or precedence) of the Apache directives such as Location(LocationMatch), DirectoryIndex, RewriteRule(in .htaccess) is important to understand the behavior when handling a specific url.

  • Before going through .htaccess, DirectoryIndex has already been applied, so rewriterule can match a pattern against index.html for proper redirection.
  • If there is [F] or [G]  in rewriterule, the 403 or 410 redirection won’t occur immediately. Instead, Location(or LocationMatch) directive in .conf file is applied. If there is an ErrorDocument 403 or ErrorDocument 410 in the Location container, it will output the document specified there. If there is no such directives in the Location container, the redirection specified in rewriterule happens. That is to say, the ErrorDocument in Location takes precedence over rewriterule. Note that the pattern specified in Location(or LocationMatch) is matched against the original url before DirectoryIndex is applied.
  • If there is no [F] or [G] for the rewiterule,  the redirection specified by rewriterule in .htaccess takes effect.
Posted in tips of hosting