Skip to content

Instantly share code, notes, and snippets.

@fmtarif
Last active July 9, 2021 00:59
Show Gist options
  • Select an option

  • Save fmtarif/bf9503530a8d425ab8a2 to your computer and use it in GitHub Desktop.

Select an option

Save fmtarif/bf9503530a8d425ab8a2 to your computer and use it in GitHub Desktop.
#htaccess HTTP Basic authentication excluding specific url
# Basic authentication for site excluding specific url patterns
# Do the regex check against the URI here, if match, set the "allow" var
SetEnvIf Request_URI ^/api allow
SetEnvIf Request_URI ^/uploads allow
AuthType Basic
AuthName "restricted area"
AuthUserFile /home/.htpasswd #chage to your .htpasswd file ABSOLUTE path
# Setup a deny/allow
Order Deny,Allow
# Deny from everyone
Deny from all
# except if either of these are satisfied
Satisfy any
# 1. a valid authenticated user
Require valid-user
# or 2. the "allow" var is set
Allow from env=allow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment