Grimka
Grimka

Reputation: 51

htaccess, auth to use index.php but allow some folder without any auth

First time I post something here, usually I find what I need, I hope you could help me and maybe it'll help others too.

I have a hand made mvc (only php/html/js/bootstrap) and I need to restrict few access but allow others, I tried few answers but nothing seems to work in my case.

Here is my directory structure :

Directory structure

So here is my problem, I want people to auth to allow access to index.php and all of the directories. This part is fine and very easy to setup. But I also need to allow them to access 3 folders without any auth ("/datas", "/datasProd" and also "/jeux"). I tried to add some htaccess in those folders where i wrote this in order to allow everyone :

Order Allow,Deny
Allow from all

And here is my root htaccess

<Files index.php>

AuthUserFile "<path to my htpasswd>"
AuthName "Accès Restreint"
AuthType basic
require valid-user

</Files>

Order Allow,Deny
Deny from all

With this config I must auth to access index.php but I must auth too if I want to access the content of datas, datasProd, and jeux. I think the problem come from my root htaccess but I can't find out what's going wrong :/

I tried to be as clear as possible but ask me if you need more information about my setup.

Thanks for help ! and sorry for my english...

Upvotes: 4

Views: 656

Answers (2)

Grimka
Grimka

Reputation: 51

Finally I found the solution, easier than I though,

In my main htaccess, I got :

AuthType Basic
AuthName 'Acces Admin'
AuthUserFile "/home/www/fabrique/www/jeuxjuniorAugustins/.htpasswd"
Require valid-user

And in each folders I want to allow access i added this small htaccess file

Satisfy any

I was just missing the correct syntax. Now I must log on to access index.php and all folders but not for the ones where I put the small htaccess.

Upvotes: 1

Victor Radu
Victor Radu

Reputation: 2292

hello set en environment variable for the requests you what to allow: here an example for the folder "permitted"

SetEnvIf Request_URI 'permitted' allow

AuthType Basic
AuthName 'dev access'
AuthUserFile /var/www/htdocs/.htpasswd
Require valid-user

Allow from env=allow
Deny from all
Satisfy any

Upvotes: 0

Related Questions