If you have self hosted WordPress and always got lots of spam comments and getting frustrated by trashing them each day, you may actually block or reduce them through your .htaccess Apache configuration file.

Most spammer attack your comment box not through the blog post but they actually access through your wp-comments-post.php file. Here is how you can stop them from attacking your blog with spam and at the same time stopping the unnecessary server load.

You can find the .htaccess file  in your root of WordPress installation folder have a basic setting written and there’s no existing security configuration on it.

Just add the rules as below. The source code as below was obtained from AllGuru.Net,

# 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.

Author:

Mick Genie is the assistant technical manager for WPWebHost and he has been playing around with WordPress and Linux infrastructure since he started as hosting support engineer since join WPWebHost. He is also the author for http://www.mickgenie.com

9 Comments

  1. After the last Akismet update my blogs didn’t receive a single spam comment. So I guess it does a pretty good job too, but it never hurts to get one more way to immune your precious blogs from spammers. Has anyone tried this method already?

  2. I tried your tutorial but it doesnt work. I think its working only from Apache based site. Right? Anyway great work sir, this would prevent automated SEO softwares for commenting.

  3. @TechStation BG It’s another way to prevent spam :D

    @Bogart Yes, these is applied for Apache based, IIS 6.0 ISAPI rewrite and IIS7 APE sites. Not for other web services. :)

  4. Wow very simple method.. Thanks for sharing. The spammers will be die lol.

  5. Why all this pain, go use some plugins.

  6. Dinesh, relying too much on plugins is not good.

  7. Thanks buddy I will try it on my site.

  8. g too much on plugins is

  9. Thanks for nice post, i will try this then i will post here with results.

    keep writting good articles!

Trackbacks/Pingbacks

  1. إمنع التعليقات المزعجة والسبام عن مدونتك باستخدام ملف .htaccess | قوالب - [...]  Block WordPress spam comment with .htaccess [...]
  2. إمنع التعليقات المزعجة والسبام عن مدونتك باستخدام ملف .htaccess | قوالب - [...]  Block WordPress spam comment with .htaccess الوسوم: .htaccess, منع التعليقات المزعجة, منع التعليقات المزعجة في الوردبريس, منع السبام, منع …
  3. إمنع التعليقات المزعجة والسبام عن مدونتك باستخدام ملف .htaccess | قوالب - [...]  Block WordPress spam comment with .htaccess هذه التدوينة نُشرت ضمن التصنيف تطوير وردبريس، مميز بواسطة قوالب وتحمل …

Leave a Comment

Feedback Form
Customer Feedback