Snippets → htaccess
Block/reduce WordPress spam comments via .htaccess
Akismet key is a useful tool to prevent spam comments, however, it is not a possible solution for every WP site, so another easy (cut n paste) solution is this htaccess snippet that blocks spam comments.
Most spammers attack your site form “wp-comments-post.php”, at the same time you prevent extra load on your server.
Paste this code into your .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post.php*
RewriteCond %{HTTP_REFERER} !.*yourdomainname.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]
</IfModule>
Hi,
Ok, so if I have no referer, I can’t post comments. Right ?
Thanks.
Regards.
I think with this one more line, just before the first http_referer condition, it’s better :
RewriteCond %{HTTP_REFERER} !^$
So, the final code could be :
RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !.*yourblog.com.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) http://yourblog.com [R=301,L]
I’m not sure but I use it on my own blog, and it works …