0

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

I'd like to setup a 301 redirect from *.oldsite.com -> *.newsite.com. 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.

2 Answers 2

1

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

    server {
      listen 80; 
      server_name .oldsite.com;

      if ($host ~ ^(\w+)\.oldsite\.com$) {
        return 301 https://$1.newsite.com$request_uri;
      }
      return 404;
    }
0

see nginx docs for regex

I haven't tried it, but it should look something like this...

    if ($host ~ (.+)\.some\.domain$) {
        return 301 http://$1.other.domain/;
    }  

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .