gpt4 book ai didi

regex - 如何匹配 RewriteCond 中的子目录?

转载 作者:行者123 更新时间:2023-12-04 14:37:17 25 4
gpt4 key购买 nike

使用正确的 RewriteCond 正则表达式时遇到问题

RewriteCond %{REQUEST_URI} !^/foo/

按预期工作,也就是说,不会将以下重写应用于所有以/foo/开头的 URL。
RewriteCond %{REQUEST_URI} !^/foo/bar/

另一方面,它不像我期望的那样工作。以/foo/bar/开头的 URL 仍在重写。

如何输入正确的正则表达式以排除子目录?

最佳答案

也许这是应用规则的内部重定向的新 URL。 L flag这样做。

[…] if the RewriteRule generates an internal redirect (which frequently occurs when rewriting in a per-directory context), this will reinject the request and will cause processing to be repeated starting from the first RewriteRule.



如果您想确保初始 URL 路径不是以“/foo/bar”开头,请检查 request line (参见 THE_REQUEST variable ):
RewriteCond %{THE_REQUEST} !^[A-Z]+\ /foo/bar/
RewriteRule …

关于regex - 如何匹配 RewriteCond 中的子目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/839575/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com