Nginx : Force Redirect WWW To Non-WWW Domain

We now how redirect old domain name to new domain name in Nginx. In this article I will explain how to permanently redirect www to non-www domain for example: to

For good SEO purposes you can easily redirect www to non-www domain using following syntax.

Force Redirect WWW To Non-WWW Domain

Edit the nginx.conf file to force www to non-www domain.

# vim /etc/nginx/nginx.conf

### redirect www to non-www with client code 301 ###
      if ($host = '' ) {
         rewrite  ^/(.*)$$1  permanent;

Save and close the file.

Reload Nginx

# service nginx relaod


Open your browser and type the below url

It should be redirected to


Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author


Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment