block spam comments on wordpress with .htaccess

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_URI} .wp-comments-post\.php*
RewriteCond %{HTTP_REFERER} !.*xyz.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]

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.

Related posts:

Partner with Us

We are providing an exclusive partnership offer to individuals and companies who are interested in setting up their own web design & development company. For more information about how to partner with us, please contact us