Support

Directory protection

To protect a certain website directory with a username and password combination, you have to create a .htaccess and a .htpasswd file. 

For demonstration purposes we use the domain name hieruwdomein.nl. When you create your .htaccess and .htpasswd files you have to replace this with your own domain name.

The .htaccess file launches a popup window when a visitor tries to access the protected directory. The popup window asks the visitor for his/her username and password. 
In the .htpasswd file username and password combinations are stored for gaining access to the protected the directory.

The .htaccess must be placed inside the directory you wish to protect, for example we have a directory called login and we upload the .htaccess file to /var/www/www.hieruwdomein.nl/pub/login/

The .htpasswd file has to be created with the htpasswd command inside the directory /var/www/www.hieruwdomein.nl/.

To use the .htpasswd command, you have to logon to your account using SSH.

The .htaccess file

Create a new file with your text editor, enter the following lines, save it as .htaccess and upload it to the directory you want to protect:

AuthUserFile /var/www/www.hieruwdomein.nl/.htpasswd
AuthGroupFile /dev/null
AuthName 'Members only'
AuthType Basic

require valid-user
ErrorDocument 401 /401.html
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html

The ErrorDocument lines are optional, you don't have to use them in your .htaccess file, only if you want to redirect visitors to your own error documents in case they use a wrong username or password. 

The .htpasswd file

This file contains the usernames and passwords for users that have access to your protected directory. Usernames and passwords are listed like (note: the passwords are encrypted) :

niels:IRSDDSREOSDGPU
anne:HSDSCaCRmEsd

Create or change usernames and passwords:

First logon by using SSH to your account and go to the location of the .htpasswd file (this is indicated in your .htaccess file by the line AuthUserFile) .

cd /var/www/www.hieruwdomein.nl/

Create the .htpasswd file with the following command:

htpasswd -c .htpasswd username
You will be prompted for a password for that user, the password will be encrypted immediately!

Add or change usernames and passwords:

htpasswd .htpasswd username