【发布时间】:2018-02-14 14:05:55
【问题描述】:
我正在尝试编写 URL 重写以从 URL 中删除重复的斜杠。
在以下其他答案之后:
我有这个代码
merge_slashes off;
rewrite (.*)//(.*) http://example.com/$1/$2 permanent;
但是,这与 URL 中任何数量的重复斜杠都不匹配。
这是我的测试网址
/page1/content.html # shouldn't match
/page1//content.html # should match and rewrite
/page1///content.html # should match and rewrite
我已经尝试过这些不同的正则表达式字符串:
(.*)//(.*)
(.*)/+/(.*)
(.*)//+(.*)
^(.*)//(.*)$
^(.*)/+/(.*)$
^(.*)//+(.*)$
"(.*)//(.*)"
"(.*)/+/(.*)"
"(.*)//+(.*)"
"^(.*)//(.*)$"
"^(.*)/+/(.*)$"
"^(.*)//+(.*)$"
它们都不匹配。
使用正则表达式测试器,我可以看到我的正则表达式是有效的并且自己匹配:https://regex101.com/r/U8nghO/1/
我做错了什么?
这是我的完整配置文件:https://paste.ngx.cc/286d5a2ecfc30152
【问题讨论】:
-
嘿,我也面临同样的问题,您能建议我如何防止这种情况发生