Manuel
Manuel

Reputation: 9522

.htaccess Condition only apply authentification to staging domain

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?

Upvotes: 1

Views: 337

Answers (1)

anubhava
anubhava

Reputation: 785098

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

Upvotes: 1

Related Questions