Core doc says: If multiple (non-regular expression) <Directory> sections match the directory (or one of its parents) containing a document, then the directives are applied in the order of shortest match first, interspersed with the directives from the .htaccess files. I have two Directory directives with the same path (in realty the second one is in an Include that is used by all vhost configs) Request URI: http://subtwo.wp/blog/ My config: DocumentRoot "/var/www/subtwo/2" <Directory "/var/www/subtwo/2"> # Core permalinks RewriteRule "^index\.php$" - [END] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule "^" "index.php" [END] </Directory> <Directory "/var/www/subtwo/2"> RewriteRule "^blog/$" "/some-url" </Directory> End up in /some-url: init rewrite engine with requested uri /blog/ pass through /blog/ [perdir /var/www/subtwo/2/] add path info postfix: /var/www/subtwo/2/blog -> /var/www/subtwo/2/blog/ [perdir /var/www/subtwo/2/] strip per-dir prefix: /var/www/subtwo/2/blog/ -> blog/ [perdir /var/www/subtwo/2/] applying pattern '^blog/$' to uri 'blog/' [perdir /var/www/subtwo/2/] rewrite 'blog/' -> '/some-url' [perdir /var/www/subtwo/2/] trying to replace context docroot /var/www/subtwo/2 with context prefix [perdir /var/www/subtwo/2/] internal redirect with /some-url [INTERNAL REDIRECT] /redir#1] init rewrite engine with requested uri /some-url /redir#1] pass through /some-url /redir#1] [perdir /var/www/subtwo/2/] strip per-dir prefix: /var/www/subtwo/2/some-url -> some-url /redir#1] [perdir /var/www/subtwo/2/] applying pattern '^blog/$' to uri 'some-url' /redir#1] [perdir /var/www/subtwo/2/] pass through /var/www/subtwo/2/some-url The other way around: Config: DocumentRoot "/var/www/subtwo/2" <Directory "/var/www/subtwo/2"> RewriteRule "^blog/$" "/some-url" </Directory> <Directory "/var/www/subtwo/2"> # Core permalinks RewriteRule "^index\.php$" - [END] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule "^" "index.php" [END] </Directory> Ends up in /index.php: init rewrite engine with requested uri /blog/ pass through /blog/ [perdir /var/www/subtwo/2/] add path info postfix: /var/www/subtwo/2/blog -> /var/www/subtwo/2/blog/ [perdir /var/www/subtwo/2/] strip per-dir prefix: /var/www/subtwo/2/blog/ -> blog/ [perdir /var/www/subtwo/2/] applying pattern '^index\\.php$' to uri 'blog/' [perdir /var/www/subtwo/2/] add path info postfix: /var/www/subtwo/2/blog -> /var/www/subtwo/2/blog/ [perdir /var/www/subtwo/2/] strip per-dir prefix: /var/www/subtwo/2/blog/ -> blog/ [perdir /var/www/subtwo/2/] applying pattern '^' to uri 'blog/' [perdir /var/www/subtwo/2/] RewriteCond: input='/var/www/subtwo/2/blog' pattern='!-f' => matched [perdir /var/www/subtwo/2/] RewriteCond: input='/var/www/subtwo/2/blog' pattern='!-d' => matched [perdir /var/www/subtwo/2/] rewrite 'blog/' -> 'index.php' [perdir /var/www/subtwo/2/] add per-dir prefix: index.php -> /var/www/subtwo/2/index.php [perdir /var/www/subtwo/2/] strip document_root prefix: /var/www/subtwo/2/index.php -> /index.php [perdir /var/www/subtwo/2/] internal redirect with /index.php [INTERNAL REDIRECT] Is this behavior just undocumented or buggy? Thans.
https://httpd.apache.org/docs/2.4/sections.html also says: If multiple <Directory> sections apply to the same directory they are processed in the configuration file order.
Does RewriteOptions Inherit change the behavior?
(In reply to Eric Covener from comment #2) > Does RewriteOptions Inherit change the behavior? Thank you very much for your comment. It solved the two Directory directives problem. I've noticed that the .htaccess in the same directory overrides the rewite rules. I've tried placing RewriteOptions Inherit into the .htaccess file at several places with no success. Could it be solved somehow?
(In reply to Szépe Viktor from comment #3) > (In reply to Eric Covener from comment #2) > > Does RewriteOptions Inherit change the behavior? > > Thank you very much for your comment. > It solved the two Directory directives problem. > > I've noticed that the .htaccess in the same directory overrides the rewite > rules. > I've tried placing RewriteOptions Inherit into the .htaccess file at several > places with no success. > Could it be solved somehow? I would have thought it would behave the same -- the htaccess rules replace the matching <Directory> rules unless you tell it to inherit in that rewrite-specific way.
> I would have thought it would behave the same -- the htaccess rules replace > the matching <Directory> rules unless you tell it to inherit in that > rewrite-specific way. Thank you again. A temporary word-aroung could be to use the DirectoryMatch directive as it will surely override directory rules. http://httpd.apache.org/docs/2.4/sections.html#merging
A strange (for me at least) fact is: Rewrite order is: DirectoryMatch -> .htaccess -> Directory But if any of these matches - regardless of [L] or [END] - rewrite processing stops there.