Skip to content

Instantly share code, notes, and snippets.

@dennisfaust
Created July 26, 2011 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dennisfaust/1108309 to your computer and use it in GitHub Desktop.
Save dennisfaust/1108309 to your computer and use it in GitHub Desktop.
Apache Basic Authentication for a Rewrite Condition Not a Directory
# Apache Basic Authentication for A Rewrite Condition not a Directory
#
# NOTE: Locations work off of URLs not directories
#
# Put this in your virtualhost block
#
<Location /YOUR_URL_PATH/>
AuthType Basic
AuthName "Authorization Required."
AuthUserFile /etc/httpd/conf/htpasswd
require valid-user
</Location>
RewriteCond %{LA-U:REMOTE_USER} !^$
RewriteCond %{SCRIPT_FILENAME} ^/YOUR_URL_PATH/(.*)
#This is for HAProxy your destination will be different
RewriteRule ^.*$ http://127.0.0.1:86%{SCRIPT_FILENAME} [P,QSA,L]
# To create your password file...
# htpasswd -c /etc/httpd/conf/htpasswd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment