问题描述
我对 nginx 非常不熟悉,作为预警,并且在他们使用的正则表达式系统上也找不到任何实际引用.所以现在对我来说这是一个黑匣子.
I am very unfamiliar with nginx, as a forewarning, and also can't find any actual references on the regex system they use. So right now it's a black box to me.
我想要做的就是将试图访问 www.mydomain.com/mydirectory/X 的用户重定向到 www.myotherdomain.com/X.
All I want to do is redirect a user trying to go to www.mydomain.com/mydirectory/X to www.myotherdomain.com/X .
似乎我应该使用 rewrite 命令,但正则表达式的语法让我望而却步.
Seems like I should be using the rewrite command but the syntax of the regex is eluding me.
提前致谢.
推荐答案
我提出了一个有效的解决方案.在发布这个问题之前我已经有了它,但没有意识到我需要重新启动 nginx.将以下内容放入服务器块中.
I made a solution that works. I had it before posting this question but didn't realize I needed to restart nginx. Put the following inside your server block.
rewrite ^(/mydirectory/)(.*)$ http://www.myotherdomain.com/$2 permanent;
这篇关于nginx - 将某个路径重定向到另一个域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!