Htaccess deny specific get parameter

半腔热情 提交于 2019-12-25 13:09:24

问题


I want to do deny access to specific ip. I tried this htaccess code but didn't worked:

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

where XXXX is an ip address. how can I do something like that, so it will deny only specific get parameter and not the whole file?


回答1:


Your pattern in Files directive is misleading. If you want to match the URL with action=deny query argument; you'd need to use <Location>:

<Location /index.php?action=deny>



回答2:


In 2.4, use to check the query string

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

In 2.2, use mod_rewrite:

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



回答3:


You can use this rule in your root .htaccess:

RewriteEngine On

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

Replace 11.22.33.44 with your actual IP address



来源:https://stackoverflow.com/questions/31903448/htaccess-deny-specific-get-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!