Ngnix Redirect To WWW

Updated: 19 April, 2018 seen 1,208

You already probably know that search engines (Google) see www as a separate domain. If you are not using 301 redirects you might get penalized for duplicate content. Anyway - the topic of this article is not an SEO lesson, but a solution how to permanently redirect non www to www  

Since I'm running on Ngnix, I'll share how to achieve this on Ngnix. Sorry Apache friends!

How To Redirect in Nginx all Domain Name Versions to https://www

Add a line to your server config: 

sudo nano /opt/etc/nginx/sites-available/


server {
rewrite ^(.*)$1 permanent;

Restart Nginx

sudo /etc/init.d/nginx restart

Let me know how does it go!