0

I have around 50 identical domains names with different tld like: domain.net, domain.org, domain.de, domain.biz, domain.ca... now I would like to forward all incoming requests to this domain with and without www on nginx to: http://domain.com how I can do this without need to list every domain?

Something like: forward all request to .domain. or domain.* to: http://domain.com permanent

2 Answers 2

2

Use nginx server_name directive with wildcards. Example:

server { 
  server_name domain.com; 

  ... real server ...
}

server { 
  server_name domain.* www.domain.*; 
  rewrite ^ $scheme://domain.com$request_uri? permanent; 
}
2
  • The order doesn't matter for the reason you stated. Wildcard server name entries are only checked if no exact match is found. However, it does matter if no server_name matches, in which case you may want the order reversed, so the redirecting server would still redirect to the desired name. The answer is still a good one, but you should probably remove that comment.
    – kolbyjack
    Jun 9, 2011 at 18:34
  • You are absolutely right, I've missed the fact that static names matched before wildcard domains. I've removed this misleading comment.
    – AlexD
    Jun 10, 2011 at 3:08
0

I never checked using a catch all tld but its worth a try. Don't have access to any nginx install right now, so if you can try the following do let me know too if it worked or not.

server {

            listen   80;
            server_name  domain.* *.domain.*;
            rewrite ^/(.*) http://domain.com/$1 permanent;

}

You must log in to answer this question.

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