Reduce Comment Spam By Protecting Your WP-Comments-Post.php File

Written by on November 1, 2011 in WordPress Tutorials - No comments

I came across a useful tip by AllGuru from a year ago that I thought I would share with you all. In the article they showed several solutions that you can implement through .htaccess to protect make your website more secure.

The one that grabbed my attention reduces comment spam by protecting your wp-comments-post.php file from spam bots. The wp-comments-post.php is the file that spam software accesses in order to leave comments on your blog. If you are sick of getting pointless irrelevant comments from spammers, add the following code to your .htaccess file, making sure that you change yourwebsite.com to your website domain.

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

If you are unsure about any aspect of this, please let me know.

Thanks,
Kevin

About

Kevin Muldoon is a Scottish webmaster and blogger who currently lives in Bogota, Colombia. He has an unhealthy obsession with trying out new WordPress themes and plugins and spends too much time in the WordPress Forums.

Post comment as twitter logo facebook logo
Sort: Newest | Oldest