nEMESIS4
11-07-2001, 10:13 AM
I've searched the board and couldn't seem to find an answer, so sorry if I repeat a question already asked. How do I use on .htaccess file to password protect specific directories.
For example, pretend this is my directory structure:
/home/sites/site1/web/
/home/sites/site1/web/folder1 *
/home/sites/site1/web/folder2
/home/sites/site1/web/folder3 *
I want to be able to place ONE .htaccess file in the /home/sites/site1/web directory. But want all the directories with *'s beside them to be password protected.
If I were to place the following .htaccess file in all those directories it would give the same effect as what I'm trying to accomplish with one file
-----
AuthUserFile /home/sites/site1/.htpasswd
AuthGroupFile /dev/null
AuthName "Restricted"
AuthType Basic
<Limit GET POST>
require valid-user
</Limit>
-----
If I just uploaded the above .htaccess file to all those directories it would work perfectly fine, but since there won't just be 2 I need protected I would like to be able to do it from one file that will be generated on the fly.
Any ideas?
Chicken
11-07-2001, 11:04 AM
I don't know of any way to place an .htaccess file in a folder and exclude certain folders (which is what you seem to want).
nEMESIS4
11-07-2001, 11:08 AM
/home/sites/site1/web/
/home/sites/site1/web/folder1 *
/home/sites/site1/web/folder2
/home/sites/site1/web/folder3 *
The .htaccess file needs to be placed in /home/sites/site1/web, only the directories with *'s beside them need to be password protected.
Using this seems to work,
<Files folder1>
<Limit GET POST>
require valid-user
</Limit>
</Files>
But the only problem with that is it password protecteds /folder1, but not /folder1/folder5 or /folder1/folder5
If I could get it to password protect folder1 along with all it's subdirectories that method would work perfecting fine.
CmptrWz
11-07-2001, 04:03 PM
Looks to me like you want <Directory ...> instead of <Files ...>
nEMESIS4
11-07-2001, 04:07 PM
Directory doesn't seem to work inside of .htaccess files. Or am I wrong on that?
pitchford
11-07-2001, 05:09 PM
To the best of my knowledge, it won't work... Reasoning: (which is logical to me, may not be correct)
Protected: http://dom.com/prot/
You want UnProtected: http://dom.com/prot/public/
In order to access "public/" you must go through "prot/"
You can setup http://dom.com/general/public
& http://dom.com/general/prot
and protect the "prot/" directory....
Like I said, seems logical.:D
nEMESIS4
11-07-2001, 05:14 PM
Thanks for the advice, but I think your mixing up what I'm asking.
I would like the folders listed below with *'s BESIDE them to be password protected, along with all subfolders within them:
/home/sites/site1/web/
/home/sites/site1/web/folder1 *
/home/sites/site1/web/folder2
/home/sites/site1/web/folder3
/home/sites/site1/web/folder4
/home/sites/site1/web/folder5 *
/home/sites/site1/web/folder6 *
/home/sites/site1/web/folder7
I want to run everything from on .htaccess file, rather than placing them inside of all the pages I want protected. In this example I would have to place 3 .htaccses files in folder1, folder5, and folder6.
Where I would like ONE .htaccess file placed in the root directory, that would password protect folder1, folder5, folder6 BUT BUT BUT leave folder2, folder3, folder4, and folder7 open for access.
Kinda understand? Thanks.
CmptrWz
11-07-2001, 07:32 PM
You are correct, directory is not allowed in .htaccess. I am used to server config files......
I think this might work:
<Files ~ "/(folder1|folder5|folder6)*$">
AuthUserFile /home/sites/site1/.htpasswd
AuthGroupFile /dev/null
AuthName "Restricted"
AuthType Basic
require valid-user
</Files>
My syntax may be wrong, and I have not tested that, but I think it is what you want, or very close to it.
nEMESIS4
11-07-2001, 08:01 PM
CmptrWz: Looks like you were on the right track there. Similar to some things I've seen, but still didn't work. I tried playing around with it a bit and got nothing. Anybody maybe notice something out of wack?
Thanks very much though.
CmptrWz
11-07-2001, 10:50 PM
I know that if you replace the "Files ~" with "FilesMatch" it is supposed to work better. And I probably screwed up the statement there, which would be the problem.