Htaccess 拒绝特定的获取参数

Htaccess deny specific get parameter

我想拒绝对特定 ip 的访问。我尝试了这个 htaccess 代码但没有成功:

<Files "index.php?action=deny">
Order Allow,Deny
Deny from XXXX
Allow from all
</Files>

其中 XXXX 是一个 IP 地址。我怎样才能做这样的事情,所以它只会拒绝特定的获取参数而不是整个文件?

您在 Files 指令中的模式具有误导性。如果要将 URL 与 action=deny 查询参数匹配;你需要使用 <Location>:

<Location /index.php?action=deny>

2.4中,用于检查查询字符串

<If "%{QUERY_STRING} =~ /action=deny/">
  Require all denied
</If>

在2.2中,使用mod_rewrite:

RewriteEngine ON
RewriteCond %{QUERY_STRING} action=deny
RewriteRule index.php - [F]

您可以在根 .htaccess 中使用此规则:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^action=deny$ [NC]
#RewriteCond %{REMOTE_ADDR} =11.22.33.44
RewriteRule ^index\.php$ - [F]

11.22.33.44替换为您的实际IP地址