How To Block Spammer/Bot IP Address Using .htaccess Method

How To Block Spammer/Bot IP Address Using .htaccess Method

Share on facebook
Share on twitter
Share on linkedin

How To Block Spammer/Bot IP Address Using .htaccess Method: In this article, we are going to show you how to block Specific IPs via your .htaccess file and when this comes in handy is when you can identify spam commenters.

Ways on How To Block Spammer/Bot IP Address Using the .htaccess Method

Who keep coming back to your website and keep leaving comments and they are always spam. You can block them completely from your website which makes your work even easier because otherwise you have to delete all the spam comments and in the same token, you can also block spiders from Spammy websites as well.

How To Block Spammer/Bot IP Address Using .htaccess Method

So, the first thing you have to do is log into your hosting account. In this case, we are using Hostgator, your hosting you can see looks very similar to Godaddy or panels are almost same in all of them. In the next step, you need to find the option called File Manager, click on that to open it and then click on document root for the website that you want to edit.

Click on go and you will find in that subdirectory or in that listing of files and .htaccess file. If you don’t see that file, there you can create it. You can just click on Add New on the left click on or then type in .htaccess. But we have this file created – opening it – .htaccess file, all you have to do is highlight it and then click on edit and this will open. The very first part here is all about WordPress permalinks. And, we want to go a little way below that and paste in this code which is here –

# BEGIN Blacklist Undesired IPs (User and Bots)

(left pointy bracket)Limit GET POST PUT(right pointy bracket)
order allow, deny
allow from all
deny from 123.456.789.111
(left pointy bracket)/LIMIT(right pointy bracket)

# END Blacklist Undesired IPs (User and Bots)

Well, you must copy and paste this code

from there. And, this is an Apache command that blocks .htaccess from specific IPs. So, the really important line we see here is denying from this fake IP. You would want to insert the actual one you want to block and you might be wondering where do we find the IP address of people or BOTS that on a block. Well, it’s quite simple, if you log into your WordPress Dashboard, which we have done here. And, quickly we have some spam comments on the website right now.

But, when you log in, you click on comments and below each comment, it shows their IP Address. So, this individual posting of Pope Francis here, that’s a bunch of spam. So, What we can do is highlight his IP address, copy it. Go back to .htaccess file. Replace the dummy IP with one we just copied and then traffic from that IP address is no longer allowed. And, we can add multiple, all we have to do is copy this line, highlight that whole line. Click copy it and paste it in again.

And, we can, you can copy as many as you want. You can have a thousand listed there and that will greatly reduce the spam on your website. Because, often this is Patrick Surrey here, this is more than likely a spam bot. So, it went out and crawled all the websites, all the WordPress had to go, find two files and to find a comment from that. It can post its spam comments on to get these backlinks which they hope either help them with SEO or so.How To Block Spammer/Bot IP Address Using .htaccess Method

Or a website visitor will click on those as you can when we scroll down. There’s a whole bunch of IPs that we could block because these are all spam. And, we will go ahead and do that as well we don’t have to watch we do that because it’s pretty simple, because all you have to do is duplicate this line copy in the new IP and save the file for now. We are just going to block this one, we will do all the rest later and that is how you can blacklist undesired IPs via your .htaccess file. Hopefully, this article helps you. So, up here we have the default WordPress .htaccess file which you would find the root directory of your WordPress website.

So, in most cases, that’s going to be public HTML, and then you will find the .htaccess file and there or you can create one if it’s not already in there. So, what we need to do to include this properly is to move these rewrite conditions and the rewrite rule up above where we have the end of the if module statements.

We are pretty sure, it would work without that, but this ensures that it will only try to do the rewrite conditions if a mod rewrite is enabled on our patchy web server. So, you may have to make sure by going into the Apache configuration file, that mod-rewrite is enabled, that should not be too hard to do and so what it’s going to do here. A rewrite condition if any of these websites are the referral URL and that means basically if anything comes before.

Even after reading this in-depth guide related to How To Block Spammer/Bot IP Address Using .htaccess Method, still, if you are facing any questions or problems in regard with How To Block Spammer/Bot IP Address Using .htaccess Method, just make sure to let us know in the comment box below.

Also Read: How To Create Quality Backlinks To Your WordPress Website