我正在尝试将Apache .htaccessconfiguration转换为nginx。 以前的设置有很多redirect。 这些似乎大部分似乎虽然我卡在这一个:
我有一个path/support/有索引与我想要的内容,所以这工作得很好。 我有各种/support/all/types/of/things去其他领域的/support/all/types/of/things的列表 – 这些也似乎工作正常。 不过,我也需要一个/support/not-something-from-above来redirect到一个特定的域。
现在我有一个地址块填充重写像这样:
location /support { rewrite /article/229/?$ https://something.com/entries/2180 redirect; rewrite /another/?$ https://something.com/elsewhere redirect; rewrite /.*$ https://what-i-want.com redirect; }
在这个块中有更多的重写,但是想法是匹配支持下的各种path,以及它们不排队的地方,将它们发送到最后一个域。 一直以来,保持/support/url是我托pipe的index.html
我努力了:
rewrite /\w+$ https://what-i-want.com redirect; rewrite /.+$ https://what-i-want.com redirect;
我已经把它移到了它自己的位置块,特别是在/ support /下,尝试过正则expression式匹配,而且我仍然难倒了。
作为参考,.htaccess看起来像这样
RewriteRule ^support/dynamic/?$ https://something.com/entries/2180 [L,R=301,NC] RewriteRule ^support/toolbar/?$ https://something.com/elsewhere [L,R=301,QSA] RewriteRule ^support/.+$ https://what-i-want.com/ [L,R=301,NC]
您的正则expression式不够具体。 例如/.+$匹配/support 。
您可以使用rewrite...break来终止重写处理。 详情请参阅此文件 。 例如:
location /support/ { ... rewrite ^/support/$ /support/index.html break; return 302 https://what-i-want.com; }
或者,使用完全匹配位置从location /support/块中取出某些URI。 请参阅此文档了解更多 例如:
location /support/ { ... } location = /support/ { index index.html; } location = /support/index.html { }