I am trying to deploy .htpasswd
in a more scalable manner.
I have a /parent-directory/
with several .htpasswd
protected child directories:
/child-directory-1/
/child-directory-2/
/child-directory-3/
/child-directory-4/
At present each child directory contains the following files:
.htaccess
.htpasswd
index.php
and each .htaccess
file points to its accompanying .htpasswd
file.
E.g.
/parent-directory/child-directory-1/.htaccess
:
# PASSWORD PROTECT FILES
AuthType Basic
AuthName "Enter Page 1 Username and Password"
AuthUserFile /my-path/parent-directory/child-directory-1/.htpasswd
Require valid-user
etc.
Having a separate .htaccess
for each separate .htpasswd
is cumbersome however.
What I'd really like to have is a single .htaccess
file in the parent-directory:
/parent-directory/.htaccess
which then contains pointers to each .htpasswd
file for each child directory.
Is this possible?
I am messing around with:
<Files "/child-directory-1/">
AuthType Basic
AuthName "Enter your Page 1 Username and Password"
AuthUserFile /my-path/parent-directory/child-directory-1/.htpasswd
Require valid-user
</Files>
<Files "/child-directory-2/">
AuthType Basic
AuthName "Enter your Page 2 Username and Password"
AuthUserFile /my-path/parent-directory/child-directory-2/.htpasswd
Require valid-user
</Files>
and variants, but I cannot get anything to work.
Progress
I have added an .htaccess
to the /parent-directory/
, enabling me to replace the 4 index.php
files (one in each child directory) with a single index.php
file in the /parent-directory/
.
Here is the .htaccess
:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^[^\.]+$ http://%{HTTP_HOST}//parent-directory/
</IfModule>
This enables me to reduce the number of files in each child directory from 3 files:
.htaccess
.htpasswd
index.php
to 2 files:
.htaccess
.htpasswd
But... it still does not enable me to achieve the result I really want, which is ditching the .htaccess
file in each child directory.