Hi.
My site is currently working fine at the url ‘mysite.com’. I’d obviously like ''www.mysite.com to get re-directed to ‘mysite.com’ 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.
A Record:
Hostname: @
IP Adress: my.ip.address
CNAME:
Hostname(mysite): www
Hostname: @ (also tried mysite.com)
and in my htaccess:
<IfModule mod_rewrite.c> RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC] RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L] </IfModule>
Many thanks.
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
@gokay.mustafa: To enable mod_rewrite, run the following commands as root: <br><pre>sudo a2enmod rewrite <br>sudo service apache2 restart</pre>
Hi guys! Can you be more specific about it? I don’t understand how to enable mod_rewrite.
OK, this is working now - I guess I just a had to wait a bit of time for something to kick in. <br> <br>Many thanks.
Its seems the ifModule mod_rewrite tags are being stripped by the forum.
Apologies - I should have included that with my post. Here is the full mod_rewrite rule: <br> <br><IfModule mod_rewrite.c> <br> Options +FollowSymlinks <br> RewriteEngine On <br> RewriteCond %{HTTPS} !=on <br> RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC] <br> RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L] <br> RewriteCond %{REQUEST_FILENAME} !-f <br> RewriteCond %{REQUEST_FILENAME} !-d <br> RewriteCond %{REQUEST_URI} !index <br> RewriteRule (.*) index.html [L] <br></IfModule>
You have to enable mod_rewrite (a2enmod rewrite) and add RewriteEngine On before the RewriteCond’s.