Skip to content

Instantly share code, notes, and snippets.

@emarthinsen
Created June 9, 2018 19:34
Show Gist options
  • Save emarthinsen/5d2954b5bf0c11f468bef2ccf3377b37 to your computer and use it in GitHub Desktop.
Save emarthinsen/5d2954b5bf0c11f468bef2ccf3377b37 to your computer and use it in GitHub Desktop.
.htaccess if directive to force basic auth on staging
<If "(%{HTTP_HOST} =~ /staging/) && ! (%{REQUEST_URI} =~ /privacy-policy$/)">
AuthType Basic
AuthName "Staging Area"
AuthUserFile /var/app/current/public/.htpasswd
Require valid-user
</If>
@emarthinsen
Copy link
Author

I've tried simplifying this a bit using a different syntax. Here's where I'm at now:

SetEnvIfNoCase HOST        "staging"          USE_AUTH
SetEnvIfNoCase Request_URI "privacy-policy$" !USE_AUTH
AuthType Basic
AuthName "Staging Area"
AuthUserFile /var/app/current/public/.htpasswd
Require valid-user
Order allow,deny
Allow from all
Deny from env=USE_AUTH
Satisfy any

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment