Unable to get www to redirect to non-www

May 6, 2013 3.2k views
Hi. My site is currently working fine at the url ''. I'd obviously like '' to get re-directed to '' though. I've tried the various suggestions in these threads and the documentation, and unfortunately none seem to work for me - I just get an error from my internet provider when I try to view the www version, and a time-out when I try to ping it. I would be extremely grateful if you could let me me *exactly* what I have to do to get this working. This is my current set up: ------------------------------------ A Record: Hostname: @ IP Adress: my.ip.address CNAME: Hostname(mysite): www Hostname: @ (also tried and in my htaccess: RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L] Many thanks.
6 Answers
You have to enable mod_rewrite (a2enmod rewrite) and add RewriteEngine On before the RewriteCond's.
Apologies - I should have included that with my post. Here is the full mod_rewrite rule:

Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) index.html [L]
Its seems the ifModule mod_rewrite tags are being stripped by the forum.
OK, this is working now - I guess I just a had to wait a bit of time for something to kick in.

Many thanks.
Hi guys! Can you be more specific about it? I don't understand how to enable mod_rewrite.
@gokay.mustafa: To enable mod_rewrite, run the following commands as root:
sudo a2enmod rewrite

sudo service apache2 restart
Have another answer? Share your knowledge.