1

I'm using the following code to block users on my staging subdomain.

AuthName "PRIVAT"
AuthType Basic
AuthUserFile /var/www/mydomain.com/.htpasswd
require valid-user

Since I'd like to use the same .htaccess for staging and production I'd like to add an condition if HTTP_HOST = staging.mydomain.com so that only the staging environment is password prodected? Is this possible?

Manuel
  • 9,112
  • 13
  • 70
  • 110

1 Answers1

1

Good News: Yes it is possible :-)

Make use of mod_setenvif directive.

SetEnvIfNoCase Host ^staging\.mydomain\.com$ SECURED

AuthName "PRIVAT"
AuthType Basic
AuthUserFile /var/www/mydomain.com/.htpasswd
require valid-user

Satisfy    any
Order      Allow,Deny
Allow from  all
Deny from env=SECURED
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • thx anubhava! what would be the correct wrapper to put it in IfModule wrapper? would you wrappe it? What impact has SetEnvIf on performance? – Manuel Jul 09 '14 at 08:13
  • Use of `SetEnvIf` is so negligible that you won't be able to notice and yes `` would be right wrapper but worried about wrapping it. – anubhava Jul 09 '14 at 10:05