【问题标题】:nginx - redirect a certain path to another domainnginx - 将某个路径重定向到另一个域
【发布时间】:2011-03-02 08:29:21
【问题描述】:

我对 nginx 非常不熟悉,作为一个预警,并且在他们使用的正则表达式系统上也找不到任何实际引用。所以现在它对我来说是一个黑匣子。

我要做的就是将试图访问 www.mydomain.com/mydirectory/X 的用户重定向到 www.myotherdomain.com/X 。

似乎我应该使用重写命令,但正则表达式的语法让我无法理解。

提前致谢。

【问题讨论】:

    标签: regex redirect nginx rewrite


    【解决方案1】:

    我提出了一个可行的解决方案。在发布这个问题之前我已经有了它,但没有意识到我需要重新启动 nginx。将以下内容放入您的服务器块中。

    rewrite ^(/mydirectory/)(.*)$ http://www.myotherdomain.com/$2 permanent;
    

    【讨论】:

    • 无需重启。向它发送 HUP 信号以重新加载配置。
    猜你喜欢
    • 1970-01-01
    • 2020-06-28
    • 2017-11-27
    • 1970-01-01
    • 2021-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-27
    相关资源
    最近更新 更多