Monday 6 July 2015

Password Protect specific URL with htpassword

So I found this on stackoverflow here.

But here is the gist:

Enable your mod_auth, and mod_env apache modules and add the following apache directives to the Directory section of your virtual host configuration:


# Do the regex check against the URI here, if match, set the "require_auth" var
SetEnvIf Request_URI ^/pretty/url require_auth=true

# Auth stuff
AuthUserFile /var/www/htpasswd
AuthName "Password Protected"
AuthType Basic

# 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 "require_auth" var is NOT set
Allow from env=!require_auth

And reload your apache and you are a go

No comments:

Post a Comment