Question
How to make www work and redirect to non www
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.
×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 example.com
DocumentRoot …
#More stuff
</VirtualHost>
All your other urls that need to be resolved and redirected.
<VirtualHost *:80>
ServerName www.example.com
Redirect permanent / http://example.com
</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.