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.
- 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 126.96.36.199 deny from 188.8.131.52 allow from all
The above code will block two IP Address that is 184.108.40.206 and 220.127.116.11. Sometimes, spammers use a whole of a series like 18.104.22.168, 22.214.171.124 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 126.96.36.199 to 188.8.131.52
- Once you have added the code in HTACCESS file, save it and we are 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.