Skip to content

Instantly share code, notes, and snippets.

@jehanf
Created October 17, 2023 10:06
Show Gist options
  • Save jehanf/50d5b84b37e4fce8e0d8c871b4675ebd to your computer and use it in GitHub Desktop.
Save jehanf/50d5b84b37e4fce8e0d8c871b4675ebd to your computer and use it in GitHub Desktop.
Apache 2.4 conditional htpasswd auth depending on host
<IfModule mod_setenvif.c>
SetEnvIfNoCase ^HOST$ .+ unauthenticated
SetEnvIfNoCase ^HOST$ ^dev\.example\.com$ !unauthenticated
AuthType Basic
AuthName "dev.example.com"
AuthUserFile /path/to/.htpasswd
<RequireAny>
Require env unauthenticated
Require valid-user
</RequireAny>
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment