I have several RewriteRule inside <VirtualHost>, inside the <Directory> directive which belongs to the web root of said <VirtualHost> and inside .htaccess of that directory.
Question: In what order does Apache 2.4 evaluate those RewriteRules?
I tried to read Apache Docs - How the sections are merged, but I am lost and I am not sure if the rules given in that section apply to RewriteRule.
My simplified Apache config looks like this
<VirtualHost *:80> ServerName www.my-domain.tld ServerAdmin [email protected] DocumentRoot /var/www/htdocs RewriteEngine on RewriteRule "^/something" "/somewhat" RewriteRule "^/something-else" "/foo" </VirtualHost> <Directory "/var/www/htdocs"> Require all granted AllowOverride All Options FollowSymLinks RewriteEngine on RewriteRule "^something" "nothing" RewriteRule "^something-else" "bar" DirectoryIndex index.html </Directory> and the .htaccess
RewriteEngine on RewriteRule "^foo" "bar" RewriteRule "^nothing" "something" In particular, the following aspects confuses me:
.htaccessis said to overwrite<Directory>, does this mean that anyRewriteRuleinside<Directory>is completely ignored as if it was not there at all as soon as there is a singleRewriteRuleinside.htaccess?- Sections inside
<VirtualHost>are said to be evaluated after any other section in order to allow overwriting. IMHO, this statement does not make sense in case ofRewriteRule(or is at least confusing), because an earlier rewrite rule "wins".
.htacesswhen you have full admin rights and access to Apache main server configuration and setAllowOverride None. Support for.htaccessis intended for shared hosting where web masters don't have access to the main server config. See httpd.apache.org/docs/trunk/howto/htaccess.html#when - When you do need.htaccessthen simply put all your configuration in.htaccessfiles and don't use both. Inconsistency will lead to unnecessary complexity as you're already experiencing..htaccessis read on every request. But while I myself have access to the Apache config as I am the server admin, I provide web space to other uses and they have to use.htaccess. So I try to figure out how everything plays together.