I'm trying to load the .htpasswd file based on environment. If I hard code the URL it works fine.
AuthType Basic
AuthName "Password Protected"
AuthUserFile /var/www/html/sitename.dev/docroot/.htpasswd
Require valid-user
Our hosting provider is providing a global variable you can use in htaccess.
%{ENV:AH_SITE_ENVIRONMENT}
The Acquia hosting environment — possible values aredev
,test
, orprod
Using the variable we can check on which environment we currently are. If needed it can also be checked with the following rule: SetEnvIf Host ^dev\. DEV
but I would like to prevent that.
I wanted to use an IfDefine but ifdefine doesn't read global variables. Is it possible to do one of the following?
- Make the path a variable and store the path with the
AH_SITE_ENVIRONMENT
variable and then do something like this:AuthUserFile MyConfiguredPathVar
- Put a var in the AuthUserFile directly to concat like so
AuthUserFile /var/www/html/sitename.%{ENV:AH_SITE_ENVIRONMENT}/docroot/.htpasswd
- Any other way to use ifdefine and check if
AH_SITE_ENVIRONMENT = dev
Apache version 2.2.22
UPDATE 1: It's possible to check the env with RewiteCond
# Determine whether environment is production:
RewriteCond %{ENV:AH_SITE_ENVIRONMENT} !prod