.htpasswd on specific subdomain
Asked Answered
S

2

11

I have a language specific subdomain that points to the same dir as the root as my site. I use PHP to detect it and show the language.

I wish to set an htpasswd on this subdomain only. Keep in mind that there is no physical directory specific to this subdomain. Therefore the statement will be in the same htaccess as the root of my site.

I need htaccess to do this :

if request is mysubdomain.domain.com
AuthUserFile /www/.htpasswd
AuthName "Locked"
AuthType Basic

Thanks

Scientism answered 5/8, 2011 at 8:23 Comment(0)
S
23

This should work:

AuthUserFile /www/.htpasswd
AuthName "Locked"
AuthType Basic
Require valid-user

SetEnvIf Host yourdomain.com secure_content

Order Allow,Deny
Allow from all
Deny from env=secure_content

Satisfy Any

I was on the same route as @Anders Lindahl but apparently there is no "not" in SetEnvIf so I had do change it to allow from all and deny the ones with the env-var set.

His solution works too but you have to SetEnv no-auth-required 1 first and then let the !no-auth-required unset it (that's what the ! does)

Steroid answered 5/8, 2011 at 8:51 Comment(2)
Works like a charm! Thank you very much! Should get confirmed by the author :)Cameroun
This is great, I just thought Id add, this worked for me in htaccess file, but not virtualhost directive, not sure which it was ever intended, but one did so very happy :)Vasoinhibitor
T
2

This is untested, but might work or give you hints on what to lookup in the Apache documentation:

SetEnvIf Host ^mysubdomain.domain.com !no-auth-required

AuthUserFile /www/.htpasswd
AuthName "Locked"
AuthType Basic
Require valid-user
Allow env no-auth-required
Satisfy Any
Tricho answered 5/8, 2011 at 8:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.