Skip to content

Instantly share code, notes, and snippets.

@EpocSquadron
Created May 8, 2012 15:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EpocSquadron/2636437 to your computer and use it in GitHub Desktop.
Save EpocSquadron/2636437 to your computer and use it in GitHub Desktop.
Htaccess snippet for selective simple auth on staging environment.
# ##############################################################################
# # HTTP AUTH FOR NON-PRODUCTION PUBLIC SITES #
# ##############################################################################
# Set environment variable based on Host
SetEnvIfNoCase Host \.local(:80)?$ APPLICATION_ENV=development
SetEnvIfNoCase Host ^(www\.)?stagingaddress\.com(:80)?$ APPLICATION_ENV=staging
SetEnvIfNoCase Host ^(www\.)?productionaddress\.com(:80)?$ APPLICATION_ENV=production
# Check for staging so we can set DENIABLE_HOST variable
SetEnvIf APPLICATION_ENV staging DENIABLE_HOST
# Simple auth.
AuthName "Restricted Area"
AuthType Basic
AuthUserFile /server/path/to/.htpasswd
AuthGroupFile /dev/null
# Set to deny first, then allow everything unless DENIABLE_HOST is set.
Order Deny,Allow
Satisfy any
Deny from all
Require valid-user
Allow from env=!DENIABLE_HOST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment