11

struggling with mod_rewrite in apache2. Problem is that the directives are ignored when put into the httpd.conf.

If I set AllowOverride All in the sites-available/default and add the directive to .htaccess it works and each request pops up in the mod_rewrite.log.

But when I remove the .htaccess and the AllowOverride All and add the directive to the httpd.conf it's ignored.

Httpd.conf looks like this:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteLog "/var/log/apache2/mod_rewrite.log"
    RewriteLogLevel 4 
    RewriteRule ^/.* http://www.google.com                                     
</IfModule>

(Just chose google for debugging)

Phpinfo() shows mod_rewrite among the loaded modules, rewrite.load is is symlinked at /mods-enabled to mods-available, i.e., it is really there. Also, when I delete the mod_rewrite.log it is created on server start-up what IMO indicates that httpd.conf is read and mod_rewrite.c exists. But the mod_rewrite.log stays blank which would indicate that no request is sent to mod_rewrite. Additionally, when putting nonsense into the httpd.conf server won't start and throws an error.

What am I missing? Is there something like AllowOverride I have to set even for main config files?

I already played around with the / as .htaccess uses relative paths and httpd.conf doesn't. I also tried setting <Directory> tags, which does not make sense for me but still tried it to see if it changes anything ... help?!


Figured it out myself but in case someone runs into the same problem:

'Global' Rewrite-rules set in the httpd.conf have to be included in each virtual host using

<VitualHost *:80>
    RewriteEngine on
    RewriteOptions Inherit
</VirtualHost>

Otherwise they won't work in the VHosts. Also, the parent rules are applied AFTER the child rules.

0

0

Browse other questions tagged or ask your own question.