【问题标题】:Nginx redirect to another domain with diff TLDNginx 使用 diff TLD 重定向到另一个域
【发布时间】:2020-11-23 03:26:39
【问题描述】:

所以,我有两个具有不同 TLD 的域。
比如example.com和example.org

我想设置 Nginx 重定向,以便我可以将 .com 重定向到 .org
如下:

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  

【问题讨论】:

    标签: nginx redirect server configuration


    【解决方案1】:

    您可以使用带有server_name 指令的正则表达式来捕获特定的子域。详情请见this document

    例如:

    server {
        listen 80;
        listen 443 ssl;
        server_name ~^(?<subdomain>.*\.)?example\.com$;
    
        ssl_certificate ...;
        ssl_certificate_key ...;
    
        return 301 $scheme://${subdomain}example.org$request_uri;
    }
    

    【讨论】:

      猜你喜欢
      • 2013-09-25
      • 2011-03-02
      • 2019-11-25
      • 2010-10-14
      • 1970-01-01
      • 1970-01-01
      • 2012-02-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多