如果参数等于某值,则mod_rewrite拒绝访问 [英] mod_rewrite deny access if parameter equals something

查看:65
本文介绍了如果参数等于某值,则mod_rewrite拒绝访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似
的网址 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]

  1. 参数act可以在任何位置(例如http://example.com/?act=somethinggoodhttp://example.com/?mode=happy&act=somethinggoodhttp://example.com/?mode=happy&act=somethinggood&extra=yes都可以)

  1. Parameter act can be any where (e.g. http://example.com/?act=somethinggood and http://example.com/?mode=happy&act=somethinggood and http://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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆