Wednesday 3 July 2013

How to restrict the users accessing a directory

Suppose you have a domain example.com. In the document root of example.com you have a directory "confidential". And you don't want all people to access this directory. So to restrict the access to this directory except few ips. For example 192.168.1.1, 192.168.1.2, 192.168.1.3. Then  you need to follow the steps given below.

First create a file .htaccess  in  "confidential" directory.

root@amaziah [~]#cd /document root/confidential 
#touch .htaccess

Now edit .htaccess using your favorite editor

#vi .htaccess
 Order Deny,Allow
Deny from all
Allow from 192.168.1.1
Allow from 192.168.1.2
Allow from 192.168.1.3
 

Now your confidential data are safe. Only users from 192.168.1.1, 192.168.1.2 & 192.168.1.3 can access it. All others will be denied.  :)



No comments:

Post a Comment