0

I'm confused, does this additional server block will redirect ANY subdomain to https://example.com?

     server { 
         server_name www.example.com
         return 301 https://example.com$request_uri; 
     }

As far as I read it is bad practice to do it like this

        if ($host ~* ^www\.) {
            return 301 https://example.com$request_uri;
        }

But, at least in this case I'm sure that it is only rewrite if WWW is present.

Andrew
  • 105
  • 1

1 Answers1

1

The server_name directive matches on the Host request header. By specifying "www.example.com", that server block only applies to requests who's Host header matches that exact domain name.

See nginx documentation for more details.

virullius
  • 988
  • 8
  • 22