How to make www work and redirect to non www

  • Posted March 5, 2014

I was curious the best way to forward to the non www version. It seems right now www does not work at all on my site. Thanks


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

Although the other answer is not wrong (I didn’t test it), I think that is a bit harder to understand. Instead of writing it there, do it in your apache virtual hosts (mine is in /etc/apache2/sites-available/000-default.conf).

The top one has all your default stuffs: <VirtualHost *:80> ServerName DocumentRoot … #More stuff </VirtualHost>

All your other urls that need to be resolved and redirected. <VirtualHost *:80> ServerName Redirect permanent / </VirtualHost>

I placed it all in the same file since all it does is redirect. Make sure you add one to also resolve your IP. Hope this is helpful since its the second search result on google.

did you solve your issue? <br> <br>you didn’t mention yet what web server you are using because each one has different way of redirecting… <br> <br>seems like you use Aapache!!

What you do is add your domain without the “www” and then create an A record with www as the hostname and then your IP address. <br> <br>If you want to redirect www to without www use this code: <br> <br>RewriteEngine On <br>RewriteCond %{HTTP_HOST} ^$ [NC] <br>RewriteRule ^(.)$$1 [R=301,L] <br> <br>Or vice versa: <br> <br>RewriteEngine On <br>RewriteCond %{HTTP_HOST} ^$ <br>RewriteRule (.)$1 [R=301] <br> <br>Here’s a screenshot of the DNS records:

Interesting that you posted this as I am having the same exact problem. I can’t access my site via www. prefix, but without it I can.