WordPress Tweaks & Tuts?

Subscribe to TheCreatology via RSS | Email

How to block spam comments on blog using htaccess ?

by Aky Joe

If someone is continuously spamming on your website, you feel like hitting that spammer with baseball bat. Relax! Don’t do that as I have an easy way to block spam on website for you.

Block SpammerRecently, I shared an article on to block spam using Akismet Plugin on WordPress. Akismet plugin’s Spam filter is though very strong but sometimes people submit spam comments in genuine way to get back links. Being dependent on the Plugin, we are left with nothing to do but manually delete spam comments or you can use htaccess to block user to comment.

Why htaccess is useful ?

As we all are aware of htaccess file which adds security attributes to web directory where every browser reads htaccess file before loading website on client end. For instance if you want to disable web directory or password protect web directory is possible using Htaccess method. Similarly if you want to block IP Address to restrict visiting website, we will have to use htaccess method. And in this scenario we will be using htaccess code to block comment.

htaccess code to Block Spam Comment

When someone comments on your website, you can trace that person using IP Address. And if someone is spamming on website, then you can simply restrict user to access website using IP Address. Below is a simple procedure to block spam comment using htaccess.

  • Login to your WordPress Admin Area and Navigate to Dashboard > Comments.
  • In the list of comments you can get the IP Address of the users, just like in the screenshot below.
Get IP Address from User comment

IP Address from User comment

  • Once we have the IP address, we are ready to create htaccess file.
  • Go to root directory of website using FTP and look for HTACCESS file. (In some hosting it is hidden, so make sure you tweak the visibility in your FTP Client)

NOTE: Make sure you take backup of htaccess before modifying it.

  • If there is no HTACCESS file present, then you can simply create a new text file and rename it as “.htaccess”.
  • Now open HTACCESS file in any text editor and add below code to block spam comment user.

order allow,deny
deny from
deny from
allow from all

The above code will block two IP Address that is and Sometimes, spammers use a whole of a series like, and so on. In this case you can simply use the below code.

order allow,deny
deny from 121.222.238.
allow from all

Now, the above code will block whole series of IP address starting from to

  • Once you have added the code in HTACCESS file, save it and we are done.

We’re Done!

Stopping spam comments on website has always been a challenge for administrator and it will always be a ping-pong game. Let us know what measures do you use, to stop spam comments on website ? by posting a comment below.

If you have any query or further assistance is required, you can post comment as your feedback.

Similar Topics: , ,

TheCreatology Support

Got a Query? We're ready, Just Say it!

If you have a doubt or a feedback, then get-in-touch with TheCreatology Support Team now.

Start a Hangout or Email Us

Are you looking for...

  • Logo Design
  • Web Development
  • Thesis Skin Design
  • Graphic Designing
  • Virtual Assistance
Hire Us!

1 Comment

{ read them below or add one }

Jasmine November 19, 2011 at 12:12 am

thanks so much for this! A big help


Leave a Comment

Previous post:

Next post:

Contact Aky

Yes, I agree that all information above is valid.

Simple question, what's...