Can i use one .htaccess file for different folders on Linux server

.htaccessapache-2.2

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

/admin1
/admin2
/admin3

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 http://abc.com/admin

Best Answer

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

Related Topic