I can't find any documentation on Apache vhosts instructions priority / execution order between

Is there any documentation out there about the order these are going to be handled by Apache? Which one takes precedence over the other?


The general rule is that the order of the directives is important. The directive that comes first and matches wins (just like the order of the VirtualHost definitions – the first VHost is the default VHost).

In most cases it should work fine if you define Aliases/Redirects and RewriteRules first and proxy rules like ProxyPass last if you want to let redirection take place before your proxy settings apply.


Aliases and Redirects occurring in different contexts are processed like other directives according to standard merging rules. But when multiple Aliases or Redirects occur in the same context (for example, in the same <VirtualHost> section) they are processed in a particular order.

First, all Redirects are processed before Aliases are processed, and therefore a request that matches a Redirect or RedirectMatch will never have Aliases applied. Second, the Aliases and Redirects are processed in the order they appear in the configuration files, with the first match taking precedence.

For this reason, when two or more of these directives apply to the same sub-path, you must list the most specific path first in order for all the directives to have an effect.


The RewriteRule directive is the real rewriting workhorse. The directive can occur more than once, with each instance defining a single rewrite rule. The order in which these rules are defined is important - this is the order in which they will be applied at run-time.

Also see: Apache mod_rewrite Technical Details


Ordering ProxyPass Directives
The configured ProxyPass and ProxyPassMatch rules are checked in the order of configuration. The first rule that matches wins. So usually you should sort conflicting ProxyPass rules starting with the longest URLs first. Otherwise, later rules for longer URLS will be hidden by any earlier rule which uses a leading substring of the URL. Note that there is some relation with worker sharing.

Ordering ProxyPass Directives in Locations
Only one ProxyPass directive can be placed in a Location block, and the most specific location will take precedence.

Exclusions and the no-proxy environment variable
Exclusions must come before the general ProxyPass directives. In 2.4.26 and later, the "no-proxy" environment variable is an alternative to exclusions, and is the only way to configure an exclusion of a ProxyPass directive in Location context. This variable should be set with SetEnvIf, as SetEnv is not evaluated early enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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