【问题标题】:RedirectMatch rule exception using PCRE使用 PCRE 的 RedirectMatch 规则异常
【发布时间】:2014-05-10 21:44:03
【问题描述】:

我有一个有效的 RedirectRule,我想向其中添加一个例外。这是当前的 RedirectRule:

RedirectMatch (?i)/.+menu\.html$ http://www.foobar.com/foobar.html

我想将 ext3270-Menu.html 排除在此规则之外。

我在https://serverfault.com/questions/189666/make-exception-to-whole-site-redirectmatch-rule找到了以下示例:

RedirectMatch permanent ^/?((?!(thisisfoo|thisisbar)).*) https://www.foobar.com/$1

我希望在 PCRE 中比我更熟练的人可以提供符合我要求的类似内容。

谢谢

【问题讨论】:

    标签: regex apache redirect http-redirect


    【解决方案1】:

    正如你所说的PCRE,使用否定前瞻来查看你的URI 中是否没有ext3270-Menu.html

    (?i)^/(?!.*ext3270-Menu\.html).+menu\.html$
    

    Online Demo

    【讨论】:

    • 谢谢。一个问题我理解为 NOT .*ext3270-Menu\.html 后跟 .+menu\.html 到最后。如果是这样,这可以简化为 (?i)^/(?!.*ext3270).+menu\.html$
    • 是的,您可以通过这种方式进行简化。基本上它是检查if there is no ext3270 in url 然后匹配.+menu\.html$
    猜你喜欢
    • 2011-12-27
    • 1970-01-01
    • 1970-01-01
    • 2012-01-03
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 2023-03-24
    • 2011-10-19
    相关资源
    最近更新 更多