I found an interesting site the other day (forwarded to me from a colleague found here –> WizCrafts | I also found another COOL continent (then by country) IP block .htaccess download site that has block and allow IP’s here –> CountryIPBlocks.net). I decided to implement their IP block technique on my CPanel server. I happen to host on my own CPanel server (http://flophost.com if you’re interested ;) ) and as a result I have ssh access to it BUT as most CPanel hosting providers go you likely won’t!
Note, I had problems actually implementing a “global” IP block policy because of the way CPanel operates in conjunction with IPTables on my server (or so I suspect!). If I had a separate firewall I could better implement a global IP block (because it would be separate from CPanel) but I don’t for now so I’m encouraging all to follow these steps to implement the IP block not only with sites I’m using but for others who host on CPanel servers. If you don’t use CPanel you could likely tweak your .htaccess file in the same way but you’d have to figure out if that’s how your web hosting panel does things and if it doesn’t this .htaccess method should still work anyway…try it and see.
Here we go!
- Download my example file here (note it’s a text file) –> .htaccess example
- Edit the text file to meet your needs, maybe you want to delete, add or modify the list? Check WizCrafts site for updates!
- Backup your original .htaccess file, rename it to something like .htaccess.original or download it to a safe place just in case (I recommend downloading it for safe keeping and taking it off your server EVEN THOUGH you’ll get an error if trying to view it; it’s good practice to keep things tidy!)
- In the “Wizcrafts_htaccess.txt” file you’ll need to edit just a few lines to match your CPanel installation
- AuthName YOURDOMAIN.COM<–GOESHERE<–also delete the “GOESHERE” part :)
- AuthUserFile /home/yourusername/public_html/_vti_pvt/service.pwd
- AuthGroupFile /home/yourusername/public_html/_vti_pvt/service.grp
- Now upload this to your “public_html” folder, rename the “Wizcrafts_htaccess.txt” file to just .htaccess and look at your IP Deny Manager in CPanel.
* Troubleshooting, if you get an “Internal Server Error” like I did it turned out to be my comments bleeding over into being uncommented. I had a line like this…
# My cool comment, I’m blocking xyz IP’s from
such and so country
# Next comment would come along
then it would bleed over into uncommented land
Turns out that will throw the server into error because it doesn’t understand or know what “such and so country” is SO if you have an “Internal Server Error” after you implement this look over your file and make sure your comments aren’t wrapping!