【问题标题】:NGINX rewrite rule doesn't match with REGEX (.+)NGINX 重写规则与 REGEX (.+) 不匹配
【发布时间】:2020-01-18 09:01:31
【问题描述】:

我们正在尝试重写这样的链接:

https://example.com/some/thing/?tx_career_view%5BjobUid%5D=12&tx_career_view%5Baction%5D=show&tx_career_view%5Bcontroller%5D=Job&cHash=2d8595af0dfc0bf1e8b75d88849f

我们的规则如下所示:

rewrite ^/some/thing/(.+)   /some/where/else/ permanent;

在https://regex101.com/ 中,它说我们的 REGEX 匹配,但 NGINX 不会重写。

【问题讨论】:

  • 查询字符串(从? 开始的任何内容)不是用于匹配location 和rewrite 规则的规范化URI 的一部分。如果你有一个复杂的 URI 需要重写,你可以试试this answer。

标签: regex nginx parameters url-rewriting rules


【解决方案1】:

正如@RichardSmith 指出的那样,URL 参数不匹配(例如,对于您的URL,它是/some/thing/)。由于您想重写任何参数,只需使用:

rewrite ^/some/thing/  /some/where/else/ permanent;

【讨论】:

    猜你喜欢
    • 2014-05-23
    • 2015-09-24
    • 1970-01-01
    • 1970-01-01
    • 2014-10-24
    • 2018-02-01
    • 1970-01-01
    • 2010-11-20
    相关资源
    最近更新 更多