Has your website been hacked? Do you have an onerous scraper stealing your content. Or maybe you’ve been trolled or otherwise snizzled upon (don’t ask me what it means, but it sounds nasty doesn’t it?)? You can take care of those pesky little pains the arses (PITAs) once and for all just by adding a little snippet of code in your .htaccess.
Before I tell you what the code is, let’s review what an .htaccess is. It’s a little text file that allows you to overwrite some directions within your directories. You can do all sorts of things with your .htaccess including forbidding robots from crawling your site, redirecting some URLs to others, and protecting some pages with passwords. It’s a useful document.
You can create an .htaccess if your server is Apache-based. If you are on an NT server then the .htaccess won’t help you.
The code that you want to add to the .htaccess to prevent your website from being seen by certain IP addresses is this:
deny from 123.456.78.90
deny from 098.76.54.
allow from all
The first deny order (123.456.78.90) is explicit. It tells web browsers to not allow a certain IP address from viewing your website. The second order (098.76.54) tells web browsers not allow a whole block of IP addresses from viewing your website. You might use that one if you’ve noticed a family of spammers, scrapers, or hackers infiltrated you. Sometimes you’ll shut one down only to get hit by another. Blocking whole IP addresses might take care of an entire server if you need to.
To create your .htaccess, open up Notepad and save it as a blank document. Then you can write in any code you need to in order to make the changes that you want to make.