【问题标题】:Nginx config rewrite rule combinationNginx config 重写规则组合
【发布时间】:2015-04-14 02:18:32
【问题描述】:

所以我有这两条 url 重写规则。

location ~ /details {
rewrite ^/details/(.*)/(.*)/(.*)/(.*)_(.*).html$ /site/$4.$5.html permanent;
rewrite ^/details/(.*)/(.*)/(.*)/(.*)_(.*)_(.*).html$ /site/$4.$5.$6.html permanent;
}

但由于某种原因,第一个自己的作品很好,但第二个却无法接听。

有没有办法可以将这 2 个规则合并为 1 个?

感谢您的任何建议。

【问题讨论】:

    标签: .htaccess url nginx rewrite config


    【解决方案1】:

    尝试切换顺序:

    location ~ /details {
      rewrite ^/details/(.*)/(.*)/(.*)/(.*)_(.*)_(.*).html$ /site/$4.$5.$6.html permanent;
      rewrite ^/details/(.*)/(.*)/(.*)/(.*)_(.*).html$ /site/$4.$5.html permanent;
    }
    

    因为(.*) 匹配所有内容,它会吞噬所有内容,包括_ 字符,因此您的第一个正则表达式匹配第二个匹配的所有内容,因此永远不会达到第二个规则。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-04
      • 2013-08-05
      • 2013-10-12
      相关资源
      最近更新 更多