July 6, 2009

control ip access to apache via .htaccess

  1. Allow only specific ip address :

order allow,deny
deny from all
allow from 192.168.1.1
allow from 192.168.1.2

  1. Block specific ip address :

order deny,allow
allow from all
deny from 192.168.1.1
deny from 192.168.1.2

you can substitute ip for :

subnet -> deny from 192.168.1.0/24
subnet wild cards -> deny from 192.168..
domain -> deny from domain.com

you can also combine ip’s on one line:

deny from 192.168.1.1 192.168.2.1