Mar 15

Simply lock a dir for browsing, no password, using .htaccess

Category: Linux,webserver   — Published by tengo on March 15, 2009 at 4:55 am

Basically, every dir that is under your world-browsable path in your www directories will be accessible. Under normal conditions, that's exactly what you want. For example a domain pointing to /var/www/ will allow users to browse around in all subdirectories of /var/www/

Now, what if you add directories to this path you want to exclude from public access? That's where .htaccess comes in. Placing a .htaccess file in a directory will instruct the Apache webserver to use the rules in it to handle files and directories in this dir.

For example, if you want to add /var/www/ to your path, simpliy cd into /var/www/ and create a .htaccess file with these contents:

Order deny,allow
Deny from all

This will block any access to this dir, from everywhere. No fancy password checking! (There is plenty of information on how to do that out on the web...)