Markus AO Markus AO - 1 year ago 116
Apache Configuration Question

Apache httpd.conf mod_rewrite canceled if .htaccess uses mod_rewrite

Darn it took a while tracking this quirk down. I have global rewrite-rules defined in

(or in an include; won't make a difference), to force an external redirect for certain URL patterns:

<Directory "/home/*">
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^.*wrong\.php$ [R,L]

This works brilliant for any virtual host that doesn't have a
file using mod_rewrite. However, if a vhost uses any mod_rewrite rules at all, the above is not working. Even a mere
RewriteEngine on
, without any rules specified, is enough to cancel out the
rules for the vhost. Is this expected behavior? On Apache/2.2.15. I've tried with and without R & L flags, with and without a
wrapping, and declared before or after virtual hosts, but the rules simply won't work.

Someone save my sanity and tell me how to have (non-conflicting) rules in
working together. It must be possible, and I'd expect it to be the default behavior?

Edit: As requested, a sample
file: =^_^=

RewriteEngine on

Even just that and that only. Enough to make the rules not match, seems like any earlier
gets wiped out and a new clean rule set started when
kicks in. Also, any other line having to do with
causes the same. If I stick into the
RewriteRule ^([X-Z])heRmaGerd[1-3]\.FOObAR$ /wherever/$1
(with the
RewriteEngine on
, or by itself as the only line), it will surely not match, but is enough cancel out all that was defined before.

Answer Source

It looks like (at least on 2.4.6) that RewriteOptions inherit helps, placed either in httpd.conf or .htaccess.

According to docs, this should only force VirtualHost to inherit rules from main server configuration, or in per-directory context to inherit parent directory's .htaccess configuration, but I tested and it seems to resolve your issue.


Rules inherited from the parent scope are applied after rules specified in the child scope.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download