How to password protect folder/files using htaccess file?


Use the following htaccess code to enable authentication for certain files and folders from being accessed. The code has examples of password protection for a single file and password protection for a entire directory using htaccess file.

# to protect a file


AuthType Basic
AuthName “Prompt”
AuthUserFile /home/path/.htpasswd
Require valid-user


# password-protect a directory

resides
AuthType basic
AuthName “This directory is protected”
AuthUserFile /home/path/.htpasswd
AuthGroupFile /dev/null
Require valid-user


Article ID: 392
Created: Sun, Mar 14, 2010
Last Updated: Sun, Mar 14, 2010
Author: Administrator

Online URL: https://www.articlediary.com/article/how-to-password-protect-folder-files-using-htaccess-file-392.html