less than 1 minute read

Let’s say you want to make a 301 redirect from any domain (for example: www, dev, w3) of your website to direct access via the non-sub-domain url. Nginx makes it easy to do.

Just make your own wildcard server_name directive and add this to your server{} block:

if ($host != 'your_domain.com' ) {
  rewrite  ^/(.*)$  http://your_domain.com/$1  permanent;
}

Updated:

Comments