To protect a directory on the web follow these simple steps:
1. Open a .htaccess file within the directory you wish to protect
- vim .htaccess
2. Insert the followoing code:
- AuthUserFile /route/to/directory/.htpasswd
- AuthGroupFile /dev/null
- AuthName “Custom text to show in pop-up”
- AuthType Basic
- <Limit GET>
- require valid-user
3. Now we need to create the username and password:
- htpasswd -c /route/to/directory/.htpasswd username
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.
That’s it, make sure to actually change the “/route/to/directory” to an existing directory.