Site icon TheCreatology.com

How to block spam comments on blog using htaccess ?

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.

Recently, 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.

IP Address from User comment

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


order allow,deny
deny from 121.222.238.58
deny from 223.177.240.5
allow from all

The above code will block two IP Address that is 121.222.238.58 and 223.177.240.5. Sometimes, spammers use a whole of a series like 121.222.238.23, 121.222.238.24 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 121.222.238.2 to 121.222.238.254

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.

Exit mobile version