正确使用RewriteCond的正则表达式有问题
RewriteCond %{REQUEST_URI} !^/foo/
按预期工作,即在重写为以/ foo /开头的所有URL后不适用.
RewriteCond %{REQUEST_URI} !^/foo/bar/
另一方面,没有像我期望的那样工作.以/ foo / bar /开头的网址仍在重写中.
如何输入正确的正则表达式来排除子目录?
解决方法
也许这是应用规则的内部重定向的新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 firstRewriteRule
.
如果要确保初始URL路径不以“/ foo / bar”开头,请检查request line(参见THE_REQUEST
variable):
RewriteCond %{THE_REQUEST} !^[A-Z]+\ /foo/bar/ RewriteRule …