V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
shanghai1943
V2EX  ›  NGINX

nginx: 请教如何域名重定向

  •  
  •   shanghai1943 · 2022-07-21 10:57:43 +08:00 · 1462 次点击
    这是一个创建于 616 天前的主题,其中的信息可能已经有所发展或是发生改变。

    想将 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 条回复    2022-07-21 12:39:49 +08:00
    snoopyhai
        1
    snoopyhai  
       2022-07-21 11:33:10 +08:00   ❤️ 1
    livenux
        2
    livenux  
       2022-07-21 11:45:37 +08:00   ❤️ 1
    ```
    server {
    server_name ~^(?<subdomain>\w+)\.baidu.com\.com$;

    location / {
    rewrite ^ https://$subdomain.google.com.com$request_uri permanent;
    }
    }
    ```
    未作测试
    shanghai1943
        3
    shanghai1943  
    OP
       2022-07-21 12:39:38 +08:00
    @snoopyhai #1 感谢。网站里面似乎只能同域名跳转。用了 2 楼老哥方法搞定了。
    shanghai1943
        4
    shanghai1943  
    OP
       2022-07-21 12:39:49 +08:00
    @livenux #2 感谢老哥指点👍
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4115 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 10:16 · PVG 18:16 · LAX 03:16 · JFK 06:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.