Tutorial: Password-Protected Web Folder

Lock

Sometimes it is necessary to allow just selected people to access content on websites. Probably the easiest way to do this on Apache web-server is with HTAccess. Here is a short tutorial how to do it.

1. Create a file called .htaccess (notice the period in front of the name) in the folder you want to be protected.

2. Write these lines into the file:

AuthUserFile /home/user/folder/.htpasswd
AuthType Basic
AuthName "Some Description Here"
Require valid-user

The first line should point to the folder where the .htpasswd file is located. We’ll soon get back to this, leave as it is for now.

The second line describes the Authentication Type. Basic is enough for us right now.

The third line has the Authencation Name. This is just a small description, that is shown to the user when they have to input the password.

The fourth line is important, it tells Apache not to allow anyone inside this folder and it’s files without Authenticated Access.

3. Create a file called .htpasswd on the same folder as .htaccess. Open a new page and go to http://home.flash.net/cgi-bin/pw.pl .

In this website you can generate the username/password combo for your website. Type in the username and password of your choice.

On the next page, you will see bolded the text you need to insert into the .htpasswd file. Copy/paste it there.

4. In .htaccess file, first line, change the location where the .htpasswd is located. This path must be complete, i.e. to being with an /.

5. And you are done! Your password-protected web folder should be working like a charm, like this.

Posted in Web Development

Written by Kristian

Enjoy this Post?

Remember to subscribe to our RSS Feed and if you would like, please share this post.

4 Comments

  1. WoW :) Really great post. Thanks for sharing this nice post.

  2. Hey – perceptive blog, reasonable looking hither some blogs, seems a melodious unerring party line you are using. I’m currently using WordPress proper for a two of my sites but looking to change sole of them over to a stand correspond to to yours as a trial run. Anything in particular you would counsel about it?

  3. Nice resources . Thanks for sharing.

Leave a Reply