List files out of DocumentRoot and password protect it using Apache
May 13, 2008 3:26 pm apacheTo list the files in a directory with apache is very simple. All you have to do is add a directory alias to httpd.conf file. So if i want to add an alias called aliastest to directory /test i would add the following line:
alias /aliastest /test
Then i would go to my url:
http://myurl.com/aliastest
and i would see all files listed in /test directory (of course provided the permissions are set correctly). If i want to password protect it so that i can only see the files if i enter a username and password i add this to the directory section of httpd.conf;
<Directory “/test”>
Options Indexes MultiViews
AllowOverride AuthConfig
AuthName “test”
AuthType Basic
AuthUserFile /test/.htpasswd
AuthGroupFile /dev/null
require user test
Order allow,deny
Allow from all
</Directory>
Don’t forget to add a user;
# /usr/local/apache2/bin./htpasswd -c .htpasswd test
New password:
Re-type new password:
Adding password for user test
Then ensure the settings in the /Directory such as AuthUserfile is correct, restart apache and you’re good. There are many, many options for securing apache and this is very basic, so don’t go hiding sensitive information using this method.