I recently wrote about using multiple environments with GIT and ExpressionEngine. There is one last item that you likely need to manage and that is when you only want to password protect your staging environment and not your local or live environments. You generate an htpasswd file easily from here. After that, this code should help you configure your htaccess file so only your staging environement requires password authentication.

#allows everything if its on a certain host
SetEnvIf HOST "^domain.dev" dev_url
SetEnvIf HOST "^staging.domain.com" staging_url
SetEnvIf HOST "^domain.com" live_url
Order Deny,Allow

AuthName "Authorized Access Only"
AuthType Basic
AuthUserFile "/var/www/vhosts/domain.com/staging/.htpasswd"
AuthGroupFile /
Require valid-user

#Allow valid-user
Deny from all
# Allow from env=staging_url
Allow from env=dev_url
Allow from env=live_url
Satisfy any
« Back to Main