How to block users from accessing your site based on their IP address
Friday, February 29th, 2008Blocking users by IP address is pretty simple with .htaccess.
So here it is the example:
Order allow, deny
Deny from 192.168.0.10
Deny from 212.155.
Deny from 1.2.3.4 5.6.7.8 127.0.0.1
Allow from all
The default Apache order is deny,allow. So you can skip the first line in your .htaccess file if you do not need to change the order in which the Deny and Allow rules are being evaluated by the web server.
So to keep the .htaccess simple you can just use:
Deny from 192.168.0.10
Deny from 212.155.
Basically you can use such rules in your .htaccess file to block a particular user, or a network from accessing your site.
You can put several IP address in a Deny or Allow rule. For example:
Deny from 1.2.3.4 5.6.7.9
The IP addresses must be separated by a space or tab.
You can put entire networks as
Deny from 212.155.
This will block all users which IP addresses start with 212.155
Or to block all access to your site:
Deny from all
And then add another line to enable access only for yourself:
Allow from 1.2.3.4
Where “1.2.3.4” should be replaced with your computer IP address.
Posted by Mahesh ( Tryangled )