Advertisement

Password protecting directories with htaccess

Heres a quick guide to password protecting a directory on your website using the htaccess file – this tutorial is only for linux servers and you will also need shell access to your server.

First, make a file called “.htaccess” – note that there is no “filename” just an extension. You can save a file with this name in a text editor such as notepad, but using the quotations – they will stop notepad from adding .txt to the file.

Add the following to the .htaccess file:

AuthUserFile /full/path/to/.htpasswd
AuthType Basic
AuthName “My Secret Folder”
Require valid-user

Upload this file to the directory you want to be protected.

Now log on to the shell of your server, and type the following:

htpasswd -c /full/path/to_a_private/location_on_server/.htpasswd username

You will then be prompted to enter a password for that username – which will then automatically be encrypted.

Afterward set the permissions of the password file to 644.

If you want to add additional users, remove the -c attribute:

htpasswd /full/path/to_a_private/location_on_server/.htpasswd usertwo


Advertisement
SEO Powered by Platinum SEO from Techblissonline