Question
Redirect www to non www
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)
1) /etc/nginx/sites-available/wordpress
2) /etc/nginx/sites-available/default
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?
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.
×
No need to waste time with nginx settings, simply go to your advanced DNS settings, add URL redirection from www to http://yoursite.com and set the redirection type as permanent.