Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htpasswd on specific subdomain

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

like image 953
Sebastien Avatar asked Aug 05 '11 08:08

Sebastien


2 Answers

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)

like image 189
vstm Avatar answered Oct 30 '22 09:10

vstm


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
like image 33
Anders Lindahl Avatar answered Oct 30 '22 10:10

Anders Lindahl