To protect a directory on the web carry out the below steps:

1. Open a .htaccess file within the directory you wish to protect (good housekeeping)

[html]
vim .htaccess

[/html]

2. Insert the followoing code:

[html]
AuthUserFile /route/to/directory/.htpasswd
AuthGroupFile /dev/null
AuthName “Custom text to show in pop-up”
AuthType Basic

require valid-user

[/html]

3. Now we need to create the username and password:

[html]
htpasswd -c /route/to/directory/.htpasswd username
[/html]

4. You should be prompted for a password.

5. Browse to the directory in your browser and you should be prompted for your username and password.

Written by Matt Cooper
Hi, I'm Matt Cooper. I started this blog to pretty much act as a brain dump area for things I learn from day to day. You can contact me at: matt@matthewc424.sg-host.com.