Blocking bad requests with .htaccess file

眉间皱痕 提交于 2019-12-11 03:26:01

问题


I have a site that is getting hit by users hitting variations of this URL /index.php?s=

I am trying to block all requests to the following string which should get rid of all the spammers php?s=

The problem I seem to be having is the ? and = in the htaccess file are protected characters and I just can't get the syntax correct. How can I use php?s= in the following scenarios?

I have tried

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{REQUEST_URI} ^.(*php?s=).* [NC]
 RewriteRule ^(.*)$ - [F,L]
</IfModule>

and

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{REQUEST_URI} ^.*php?s=$1&%{QUERY_STRING}.* [NC]
 RewriteRule ^(.*)$ - [F,L]
</IfModule>

and

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{THE_REQUEST} ^.*(php?s=$1&%{QUERY_STRING}).* [NC]
 RewriteRule ^(.*)$ - [F,L]
</IfModule>

But nothing works. Help please!


回答1:


try

#all .php requests with s= in querystring
RewriteCond %{REQUEST_URI} ^.+\.php$ [NC]
RewriteCond %{QUERY_STRING} ^s=.*$   [NC]
RewriteRule . - [F,L]

If you want to prevent s= in any querystring location replace the 2nd rewritecond above with

#block s= in any location
RewriteCond %{QUERY_STRING} ^(.*&)?s=.*$ [NC]



回答2:


You can also try blocking them before they get to the point of executing anything

.htaccess example



来源:https://stackoverflow.com/questions/8236341/blocking-bad-requests-with-htaccess-file

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