NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
shanghai1943
V2EX  ›  NGINX

nginx: 请教如何域名重定向

  •  
  •   shanghai1943 · Jul 21, 2022 · 2364 views
    This topic created in 1390 days ago, the information mentioned may be changed or developed.

    想将 http://a.baidu.com/123 重定向到 http://a.google.com/123

    相当于把 baidu.com 这个一级域名改为 google.com

    我试了 rewrite ^http://(.).baidu.com/(.) http://$1.google.com/$2 redirect;

    貌似没效果。

    有哪位老哥能指点一下么

    4 replies    2022-07-21 12:39:49 +08:00
    snoopyhai
        1
    snoopyhai  
       Jul 21, 2022   ❤️ 1
    livenux
        2
    livenux  
       Jul 21, 2022   ❤️ 1
    ```
    server {
    server_name ~^(?<subdomain>\w+)\.baidu.com\.com$;

    location / {
    rewrite ^ https://$subdomain.google.com.com$request_uri permanent;
    }
    }
    ```
    未作测试
    shanghai1943
        3
    shanghai1943  
    OP
       Jul 21, 2022
    @snoopyhai #1 感谢。网站里面似乎只能同域名跳转。用了 2 楼老哥方法搞定了。
    shanghai1943
        4
    shanghai1943  
    OP
       Jul 21, 2022
    @livenux #2 感谢老哥指点👍
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1188 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 18:07 · PVG 02:07 · LAX 11:07 · JFK 14:07
    ♥ Do have faith in what you're doing.