Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have different folders which i want to prevent access . But i don't want to separate for different folders.

For i have htaccess and htpasswd applies to


I want that if user enter username password fro admin1 folder then he will be able to access admin2 and admin3 without entering isername and password again

But if someone only access admin2 then he has type enter username and password

SOmething like single sign on

I am accessing those via web interface

share|improve this question
up vote 2 down vote accepted

Yes, there are two options.

Option 1)
Have similar, or the same .htaccess files in every directory you wish to protect, which reference a single .htpassword file:

AuthUserFile /etc/httpd/.htpasswd
AuthName "Some Secret FIles"
AuthType Basic
require valid-user

Option 2) Symlink a single .htaccess file into every directory (This means if you change anything in your master .htaccess file all the symlinks will be updated

share|improve this answer

Instead of putting the same file in all the different folders, you could restrict access to a common parent folder instead. E. g. like this:

/parent            <-- this folder is protected by .htaccess

This way you would only have to maintain a single .htaccess file.

A different would be linking the same .htaccess file into all three folders using symlinks (if you are on a *nix based OS / on Windows you might use junctions when on NTFS). But I am not sure if Apache allows symlinks as .htaccess files

share|improve this answer

Short Answer is Yes you can use same .htaccess file.

This is how HTTP Authentication works. You can just copy same .htaccess to all three folders and the user will be able to browse all three folders with out being asked for password again. The authentication basically depend on the password file, as far as the password file is same the rest doesn't matter. It will work everywhere on your domain. So you can use the same .htaccess file.

share|improve this answer
so u mean , in every folder i copy the same .htaccess and .htpasswd file – Mirror51 May 22 '11 at 12:43
no you can just move the .htpasswd file outside of your document root. and then just change the path to .htpasswd in your .htaccess file. That way you will have single .htpasswd for all 3 directories. And when you will change/update passwords it will be reflected on all 3 directories. – Hameedullah Khan May 22 '11 at 17:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.