How to block spam IPs with htaccess
By Brian Turner
May 28, 2008
There are a number of reasons why you may want to block certain IP’s from blocking your site.
Firstly, certain IPs are commonly used for spam (blogs or forums). Others may be used by bots which are trying to run functions of your site in such a way as to crash it.
Either way, there is a simple way any webmaster running a LAMP server (Linux, Apache, MySQL, PHP) can block these IP’s directly themselves - using .htaccess.
Simply add the following lines to the .htaccess file in the root of your public_html folder:
order allow,deny
deny from 24.27.124.14
deny from 54.21.15.
allow from all
Already I’ve included two sets of IPs to help illustrate how to use this.
The first line - deny from 24.27.124.14 - tells the server to block access from the single IP 24.27.124.14.
The second line - deny from 54.21.15. - tells the server to block access for all IP’s within the range of 54.21.15.0 - 54.21.15.255.
It’s as simple as that.


Comments
Got something to say?
Visited 289 times, 5 so far today