I am trying to set up a canonical hostname, as describe in the second entry in http://httpd.apache.org/docs/1.3/misc/rewriteguide.html. However, it is not working. Using example.com as an example, where it should be www.example.com, if I go to example.com 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 ^/(.*) http://www.example.com/$1 [L,R]
I also added:
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^/(.*) http://www.example.com/$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?
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.example.com/$1 [L,R]
I also added:
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^/(.*) http://www.example.com/$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?