So, I have two domains with diff TLDs.
Like example.com and example.org
I want to set Nginx redirect so that I can redirect.com to.org
Like below:
example.com => example.org
www.example.com => www.example.org
anything.to.any.levels.example.com => anything.to.any.levels.example.org
example.com/anything/to/any/levels => example.org/anything/to/any/levels
anything.to.any.levels.example.com/anything/to/any/levels => anything.to.any.levels.example.org/anything/to/any/levels
You can use a regular expression with the server_name
directive to capture the particular subdomain. See this document for details.
For example:
server {
listen 80;
listen 443 ssl;
server_name ~^(?<subdomain>.*\.)?example\.com$;
ssl_certificate ...;
ssl_certificate_key ...;
return 301 $scheme://${subdomain}example.org$request_uri;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.