问题
I keep getting nonsense hits to my site like:
- myurl.com/?kw=antivirus*protection
- myurl.com/?kw=a+casino
- myurl.com/?kw=.confused.com
- myurl.com/?kw=whatevernonsense
Also, if it matters, it is a self-hosted Wordpress site. I've tried many permutations to the following, but it isn't working:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} kw
RewriteRule ^(.*)$ - [F,L]
</IfModule>
Edit: I've tested the above code in a separate directory, and it works fine. Below is the Wordpress chunk I've narrowed it down to:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} kw
RewriteRule ^(.*)$ - [F,L]
</IfModule>
# Use PHP5.3 Single php.ini as default
AddHandler application/x-httpd-php54s .php
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
回答1:
I was able to fix this by adding the following to the WP chunk of the .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
# These 2 lines block any request coming in with `/?kw=`
RewriteCond %{THE_REQUEST} \s/+[^?]*\?kw=
RewriteRule ^ - [F,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
来源:https://stackoverflow.com/questions/28969856/block-kw-query-string