mod_rewrite directives seem to be ignored


Active Member
Mar 1, 2007
I am trying to set up a canonical hostname, as describe in the second entry in However, it is not working. Using as an example, where it should be, if I go to it does not get rewritten. I have the following in a .htaccess:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*)$1 [L,R]

I also added:

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^/(.*)$1 [L,R]

But no change.

I was able to get an error by saying "RewriteEngine fail" but other than that, nothing in the error logs.

Why does it seem that the rewrite rules are being ignored, and how can I fix this?