Apache mod_rewrite – 未知标志 ‘AND’

huangapple go评论71阅读模式
英文:

Apache mod_rewrite - unknown flag 'AND'

问题

这些规则在apache 2.2.34上不起作用。

RewriteCond %{HTTP_HOST} !^subdomain\.domain\.com$ [NC,AND]
RewriteCond %{QUERY_STRING} ^(.*)$ [NC]
RewriteRule ^/page\.php$ - [R=404,L]

我得到 RewriteCond: unknown flag 'AND'

有其他方法可以做到这一点吗?

英文:

These rules are not working on apache 2.2.34

RewriteCond %{HTTP_HOST} !^subdomain\.domain\.com$ [NC,AND]
RewriteCond %{QUERY_STRING} ^(.*)$ [NC]
RewriteRule ^/page\.php$ - [R=404,L]

I get RewriteCond: unknown flag 'AND'

Is there any other way to do this?

答案1

得分: 1

AND 不需要(也不是有效的标志),因为条件会自动与AND连接在一起。

只需使用:

RewriteCond %{HTTP_HOST} !^subdomain\.domain\.com$ [NC]

此外,RewriteCond %{QUERY_STRING} ^(.*)$ [NC] 实际上并没有起到任何作用,它匹配了任何内容的 QUERY_STRING(包括空字符串)。

你的最终规则应该只包括这个:

RewriteCond %{HTTP_HOST} !^subdomain\.domain\.com$ [NC]
RewriteRule ^/?page\.php$ - [R=404,NC,L]
英文:

AND is not required (and not a valid flag either) as conditions are automatically ANDed together.

just use:

RewriteCond %{HTTP_HOST} !^subdomain\.domain\.com$ [NC]

Moreover RewriteCond %{QUERY_STRING} ^(.*)$ [NC] is not really doing anything and it matches QUERY_STRING with anything (including empty string).

Your final rul should be just this:

RewriteCond %{HTTP_HOST} !^subdomain\.domain\.com$ [NC]
RewriteRule ^/?page\.php$ - [R=404,NC,L]

huangapple
  • 本文由 发表于 2023年6月8日 17:38:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76430507.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定