【问题标题】:Rewrite to another TLD for all subdomains为所有子域重写到另一个 TLD
【发布时间】:2017-10-07 03:05:45
【问题描述】:

我想用nginx实现如下重写:

example.com -> example.io
*.example.com -> *.example.io

因此,与example.com 相关的任何内容都应重定向到example.io,同时保留子域(如果有的话)。

【问题讨论】:

    标签: regex http nginx url-rewriting


    【解决方案1】:

    你只需要一个简单的服务器块来监听 example.com 并重定向到 example.io

    http {
    
    map $server_name $redirect_to {
       default example.io;
       "~*^(.*)\.example.com$"  $1.example.io;
    }
    
    server {
    
    listen 80;
    
    listen 443 ssl;
    server_name example.com *.example.com;
    ssl_certificate ...;
    ssl_certificate_key ....;
    
    return 302 $scheme://$redirect_to$request_uri;
    }
    

    【讨论】:

    • 我不认为第 5 行中的波浪号应该在那里。
    猜你喜欢
    • 2013-09-25
    • 1970-01-01
    • 2019-07-02
    • 1970-01-01
    • 2011-12-16
    • 1970-01-01
    • 2020-11-23
    • 1970-01-01
    • 2017-08-31
    相关资源
    最近更新 更多