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