Nginx – Redirect wildcard subdomains


I'm new to nginx and just looking for some advice/help. I've got two domains, the original domain and the new domain

I'd like to setup a 301 redirect from * -> * I've looked at the documentation and it looks like if you actually know the subdomain you want to redirect it is easy but I can't find anything on wildcard sub-domains.

Any help/insight is really appreciated.

Best Answer

I just wanted to expand on heiko's answer, you should include request_url in the redirect.

    server {
      listen 80; 

      if ($host ~ ^(\w+)\.oldsite\.com$) {
        return 301 https://$$request_uri;
      return 404;
Related Topic