Torben
Torben

Reputation: 5494

.htaccess - Disable basic auth for specific path

I run a testsystem with a htaccess basic auth:

AuthType Basic
AuthName "Restricted Content"
AuthUserFile /var/www/html/.htpasswd
Require valid-user

I now want to disable this auth for all user who target the /api and /api/orders etc. of this server. I tried it with this:

SetEnvIf Request_URI "/api(.*)$" api_uri
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /var/www/html/.htpasswd
Require valid-user
Deny from all
Allow from env=api_uri
Satisfy any

But this does not work - mod_setenvif is enabled. Does anybody have an idea why this is not working?

Thanks!

Upvotes: 3

Views: 5750

Answers (2)

Álvaro González
Álvaro González

Reputation: 146450

I normally just add a separate .htaccess file inside the api folder:

Satisfy any

Upvotes: 1

anubhava
anubhava

Reputation: 785108

Have it this way:

SetEnvIf Request_URI /api api_uri

AuthType Basic
AuthName "Restricted Content"
AuthUserFile /var/www/html/.htpasswd
Require valid-user

Satisfy    any
Order      deny,allow
Deny from  all
Allow from env=api_uri

Upvotes: 3

Related Questions