How to Password Protect a Directory using .htaccess?
You may need to password protect a directory in order to limit the sharing of files under it OR may need to protect a private area. You can password protect a directory using a .htaccess file which has to be placed under a directory which needs to be protected.
Create a .htaccess file
vi /home/username/.htaccess
Once created, add the following lines to it:
AuthUserFile /home/username/.htpasswd
AuthName “Private Area”
AuthType Basic
require valid-user
where, ‘username’ is the actual username of your domain. Now, create a .htpasswd file under the /home/username/ directory.
vi /home/username/.htpasswd
In order to grant access to the directory for specific users, you need to place all the users along with their passwords in the below format:
username1:encryptedpassword
username2:encryptedpassword
There is no limit in adding users to this file, just make sure each user should be on a separate line and you can encrypt passwords using any available tool on the internet.
No comments:
Post a Comment