How to make www work and redirect to non www

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

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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: