Password Protect Directory htaccess

by Mike Lugar
image title

You can easily password protect a directory with htaccess. This is a very practical method if you want an easy way to secure a directory on an Apache web server to keep public visitors out.

First, you will need a .htaccess file in the directory you wish to secure. The parameters for this .htaccess file are as follows:

 

In the above example replace ‘FullPathTo‘ with the full path on the server to the .htpasswd file (which we will cover next). It is extremely important to note that this file should be placed outside your main web root folder (so that it is not accessible through the web just by FTP).

Second, you will need to create the .htpasswd file and place it in another area on the server only accessible by FTP. Here is the syntax for this file:

 

In this file each login should be on a separate line, the above example only has one login and therefore only 1 line in the .htpasswd file. It is very important that you do not store your password(s) in plain text for security reasons. The password(s) that you use should be MD5’d. You can use a number of free online MD5 hash generators for this.

Once these two files are created and uploaded to your server, the directly that the .htaccess file is in will now be secure.

 

 

Mike Lugar
Mike is the managing member at MSLtek and is an avid web consultant and web developer. He enjoys solving complex problems and helping businesses connect with technology.
Posted on September 20, 2016

Would you like us to send you a quote?

Get A Quote