Report this

What is the reason for this report?

how to removeredirect 301 or make the www as the main and non-www one with redirect

Posted on November 10, 2014

Hello, i have created my droplet with the hostname website.com(example) and then add a CNAME with www that points my site. now my site with www shows one 301 redirect. how can i change this state. i want to remove that 301 redirect from www and want to add that redirect to website.com so that anyone who type website.com lands in www.website.com and www.website.com stays without any redirect. im on ubuntu 14.04 with apache

regards



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!

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.

Assuming you are using Apache, you can set up a redirect from the non-www url to the www url by setting up a new VirtualHost that just redirects to the other one. It would look something like:

<VirtualHost *:80>
    ServerName example.com
    Redirect permanent / http://www.example.com/
</VirtualHost>

<VirtualHost *:80>
    ServerName www.example.com
    #
    # All your normal configuration
    #
</VirtualHost>

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.