How do I redirect http://www.example.com to http://example.com?
I am using LEMP, Nginx, Wordpress.
Qn 1: To which file should I add the below code to?
server { server_name www.example.com; return 301 $scheme://example.com$request_uri; }
I have a few files in mind (I followed your tutorials)
Qn 2: If I add the above code, must I still do the DNS part on CNAME (www and @)? Or can I skip this step?
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!
I think you need to add www and @ CName record to make the domain catch www, <br> <br>also, I believe you need to have each vhost like the following code: <br> <br>server { <br> server_name www.domain.com; <br> rewrite ^(.*) http://domain.com$1 permanent; <br>} <br> <br>server { <br> server_name domain.com; <br> #The rest of your configuration goes here# <br>} <br> <br>for exp. look here: http://stackoverflow.com/questions/7947030/nginx-no-www-to-www-and-www-to-no-www
Thanks for your reply! I got it to work by just by adding the CName record and without the server{…} portion. <br> <br>But what I really want to know is by adding the server{…} portion, do I still need to do the CName record? Because I actually want to do it through this method - i.e. to redirect through server {…} portion. <br> <br>If the answer is yes, I will know that such a method actually exists. and my next step would be to figure how to go about just adding the server{…} portion alone. Now I’m like a lost sheep. Because I have added CName record and it already works so i cant tell if the server {…} is actually working. <br> <br>thanks in advance!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.