After a2enmod rewrite, I wrote the file /etc/apache2/conf-available/myspecific_rewrite.conf :

RewriteEngine on
RewriteRule ^/test(/.*)?$ http://anothersite.tld/test$1 [R]
RewriteRule ^/test2(/.*)?$ http://anothersite2.tld/test [R]

Then I a2enconf myspecific_rewrite and the correct symbolic link is created in /etc/apache2/conf-enabled.

The problem is that this conf doesn't work : the rewrite is not active.

I want that rewrite to be active for all my virtual hosts. This file I wrote defines RewriteRules outside of a <VirtualHost>... is there a way to make it working?


you could use include in every VirtualHost directive pointing to the file.

Source for the info: SO comment by Jeremy Bourque

alternative you can use

RewriteEngine On

RewriteOptions Inherit

on every VirtualHost

Source: same question and Apache Docs for mod_rewrite

  • Didn't know RewriteOptions Inherit. That did the trick. – Anthony O. Jun 12 '14 at 10:21

Here is what I finally did : using mod_alias's Redirect and RedirectMatch directives.

Here is my conf file :

Redirect permanent /test http://anothersite.tld/test
RedirectMatch permanent ^/test2(/.*)?$ http://anothersite2.tld/test

Advantage : I don't need mod_rewrite anymore.

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.