views:

39

answers:

2

Hi,

What is the htaccess lines/config I would require to ensure that all parts of my site (files & URLs) are protected by authentication, EXCEPT for a given limited set of URLs. For example all except "/api/.*" if this makes sense.

The actually authentication could be like the below, but it's how I wrap this in the directives...

AuthName "Dialog prompt" AuthType 
Basic AuthUserFile
/home/site/.htpasswd Require
valid-user

thanks

+1  A: 

You could use SetEnvIf and <IfDefine>:

SetEnvIf Request_URI ^/api/ no_auth_req
<IfDefine !no_auth_reg>
    AuthName "Dialog prompt"
    AuthType Basic
    AuthUserFile /home/site/.htpasswd
    Require valid-user
</IfDefine>
Gumbo
Thanks - can I ask if there was more than one URL I didn't want protected what the syntax would look like for this?
Greg
@Greg: Adjust the regular expression pattern or use another `SetEnvIf` directive.
Gumbo
Greg
A: 

this seems to work:

AuthUserFile /home/.htpasswd
AuthName "Password Protected"
authtype Basic
Order Deny,Allow
Satisfy any
SetEnvIf request_uri "/api/" allow_all
Deny from all
Require valid-user
Allow from env=allow_all
Greg