Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude one folder in htaccess protected directory

I have a directory protected by htaccess. Here is the code I use now:

AuthName "Test Area" Require valid-user AuthUserFile "/***/.htpasswd" AuthType basic 

This is working fine. However, I now have a directory inside of this folder that I would like to allow anyone to access, but am not sure how to do it.

I know that it is possible to just move the files outside of the protected directory, but to make a long story short the folder needs to stay inside the protected folder, but be accessible to all.

How can I restrict access to the folder, but allow access to the subfolder?

like image 385
Sherwin Flight Avatar asked Jan 02 '12 05:01

Sherwin Flight


2 Answers

Just create an .htaccess file in the subdirectory with the content:

Satisfy any

like image 161
user3201334 Avatar answered Nov 04 '22 14:11

user3201334


According to this article you can accomplish this by using SetEnvIf. You match each of the folders and files you want to grand access to and define an environment variable 'allow' for them. Then you add a condition that allows access if this environment variable is present.

You need to add the following directives to your .htaccess.

SetEnvIf Request_URI "(path/to/directory/)$" allow SetEnvIf Request_URI "(path/to/file\.php)$"  allow Order allow,deny Allow from env=allow Satisfy any 
like image 27
Sudhir Bastakoti Avatar answered Nov 04 '22 14:11

Sudhir Bastakoti