如果参数等于某值,则mod_rewrite拒绝访问 [英] mod_rewrite deny access if parameter equals something
问题描述
我有类似
的网址
mydomain.com?act=somethingbad
mydomain.com?act=更糟
和
mydomain.com?act=somethinggood
mydomain.com?act=更好的东西
I have urls like
mydomain.com?act=somethingbad
mydomain.com?act=somethingworse
and
mydomain.com?act=somethinggood
mydomain.com?act=somethingbetter
我需要禁止不良行为. 尝试过类似的内容:
I need to make bad actions forbidden. Tried something like:
RewriteCond %{QUERY_STRING} act=(.*)
RewriteCond %{QUERY_STRING} act=[^(somethinggood)]
RewriteRule ^(.*) - [F]
因为我的不良行为多于良好行为,所以我想从该规则中排除不良行为. 但是上面的示例不起作用.
Because I have more bad actions than good I want to exclude de good actions from this rule. But the above example doesn't work.
推荐答案
使用以下规则:
RewriteCond %{QUERY_STRING} (^|&)act=(.*)
RewriteCond %{QUERY_STRING} !(^|&)act=(somethinggood|somethingbetter)(&|$)
RewriteRule ^(.*) - [F]
-
参数
act
可以在任何位置(例如http://example.com/?act=somethinggood
和http://example.com/?mode=happy&act=somethinggood
和http://example.com/?mode=happy&act=somethinggood&extra=yes
都可以)
Parameter
act
can be any where (e.g.http://example.com/?act=somethinggood
andhttp://example.com/?mode=happy&act=somethinggood
andhttp://example.com/?mode=happy&act=somethinggood&extra=yes
will be OK)
如果act
参数的值为空,则将被拒绝(例如,http://example.com/?act=
被视为BAD参数)
If you will have empty value for act
parameter, it will be rejected (e.g. http://example.com/?act=
is treated as BAD parameter)
根据您提供的URL示例,此规则将应用于在查询字符串中具有act
参数的所有URL.
Based on URL examples you have provided, this rule will be applied for ALL URLs that have act
parameter in query string.
这篇关于如果参数等于某值,则mod_rewrite拒绝访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!