InsideDarkWeb.com

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

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

Server Fault Asked on November 22, 2021

4 Answers

4 Answers

Try this:

#####
SetEnvIf Request_URI ^/admin1 auth=1
SetEnvIf Request_URI ^/admin2 auth=1
SetEnvIf Request_URI ^/admin3 auth=1

AuthName "Please login"
AuthType Basic
AuthUserFile /path_to_file_which_contains_user_login_pwd/.htpasswd

## first, allow everybody
Order Allow,Deny
Satisfy any
Allow from all
Require valid-user
# then, deny only if required
Deny from env=auth
#####

Answered by Nikolay Bronskiy on November 22, 2021

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

Answered by Smudge on November 22, 2021

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
/parent/admin1
/parent/admin2
/parent/admin3

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

Answered by Axel Knauf on November 22, 2021

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.

Answered by Hameedullah Khan on November 22, 2021

Add your own answers!

Related Questions

Strongswan transport mode ipsec within subnet

1  Asked on January 12, 2021 by viraptor

     

SuperMicro Servers can’t detect ALL Disk attached to SAS

0  Asked on January 11, 2021 by sami-satti

   

Zabbix key with comma

1  Asked on January 11, 2021 by pawe-zimny

 

Zabbix doesn’t run custom alert script

1  Asked on January 11, 2021 by alfred-balle

   

SQL Server 2012 Native Client returns missing DLL error on install

1  Asked on January 10, 2021 by user306594

   

How to install company proxy certificate

1  Asked on January 9, 2021 by chandima-jayawickrema

       

Windows server 2019 RRAS slow download speed

0  Asked on January 9, 2021 by selfishcrawler

     

Allow download of pdf files only in .htacces file

0  Asked on January 9, 2021 by user2033464

   

Freeradius LDAP through AP

1  Asked on January 9, 2021 by smok

     

Ask a Question

Get help from others!

© 2021 InsideDarkWeb.com. All rights reserved.