Home » Labs » block spam comments on wordpress with .htaccess  

block spam comments on wordpress with .htaccess


Filed under Labs

Are you running a WordPress site /blog and getting too many spam comments which makes you frustrated? Then you can block this with the help of .htaccess.

Most spammer attacks your blog by accessing wp-comments-post.php file. Remember that most of them never visit your site and they uses some commenting software’s with a keyword tool. This software searches on internet and finds the wp-comments-post.php files. With the help of software they can send 100 of comments within single click. So take your .htaccess file and add the following lines to it.

# Protect from spam comments
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
RewriteCond %{HTTP_REFERER} !.*xyz.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]
</IfModule>

xyz is referring to your blog root or best put your domain name by the way.

Make sure you have make a backup of your original .htaccess rules before apply the spam blocking rules to prevent unnecessary mess ups.

It's only fair to share...Share on Google+Tweet about this on TwitterShare on Facebook

Posts you may like: