Categories
Programming

Apache – Password protected Directories with Require SSL

Prepend the following code in an .htaccess file

SSLOptions +StrictRequire
SSLRequireSSL
SSLRequire %{HTTP_HOST} eq "EXAMPLE.COM"
ErrorDocument 403 https://%{HTTP_HOST}%{REQUEST_URI}?%{QUERY_STRING}

AuthGroupFile /dev/null
AuthType Basic
AuthUserFile /home/.htpasswd
AuthName "Some message..."
require valid-user
ErrorDocument 401 "Unauthorized Access"

This configuration redirects all requests to its https equivalent and will also work with password protected directories. Authentication is performed over SSL, never over http.

Check if the htpassword exists. Of not, create new users using this command

#Crypt encryption
htpasswd -bd .htpasswd USER PWD

#SHA encryption
htpasswd -bs .htpasswd USER PWD

Leave a Reply

Your email address will not be published. Required fields are marked *