我使用 RedirectMatch
规则,该规则应排除以下两个 URL:
citycards/citycards-locations/munchen/citycards-trachtenvogl-reichenbachstr-47-munchen
citycards/citycards-locations/munchen/citycards-4-you-munchen-hirtenstrasse-18-munchen
我将此规则与正则表达式一起使用,但收到 500 内部服务器错误:
RedirectMatch 301 /citycards/citycards-locations/muenchen/((?!citycards/citycards-locations/munchen/citycards-trachtenvogl-reichenbachstr-47-munchen|citycards/citycards-locations/munchen/citycards-4-you-munchen-hirtenstrasse-18-munchen ).+)$ /citycards/citycards-locations/muenchen/$1
有什么想法为什么它不起作用吗?
最佳答案
您当前的规则是:(分为多行以便更好地显示/理解):
RedirectMatch
301
/citycards/citycards-locations/muenchen/((?!citycards/citycards-locations/munchen/citycards-trachtenvogl-reichenbachstr-47-munchen|citycards/citycards-locations/munchen/citycards-4-you-munchen-hirtenstrasse-18-munchen ).+)$
/citycards/citycards-locations/muenchen/$1
基本上,您的正则表达式表示:
- 匹配
/citycards/citycards-locations/muenchen/
后面没有跟随以下内容
citycards/citycards-locations/munchen/citycards-trachtenvogl-reichenbachstr-47-munchen
,citycards/citycards-locations/munchen/citycards-4-you-munchen-hirtenstrasse-18-munchen
(18-munchen
之后有一个空格>)
- 匹配所有内容,直到 URI 结尾
并将匹配的 URI 重定向到:/citycards/citycards-locations/muenchen/$1
,这与匹配的 URL 基本相同。
我看到 2 个问题。
- 如果否定前瞻中的空格不被视为模式的一部分,则实际上是将 4 个参数传递给
RedirectMatch
指令,从而导致状态 500 错误 - 如果模式解析正确,则存在无限重定向循环。
关于regex - 排除 URL 的重定向匹配不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33867891/