Password Protecting a Single File
- Create a file called ".htapasswd" and put it above your root directory. Visitors are unable to access it in this location.
- Create an encrypted password. This can be done with a password generator tool, such as htpasswd.
- Right click the .htpsddwd file, click "Code Edit".
- Click "Edit".
- Paste the generated password information into the .htpasswd file.
- Click "Save Changes", then "Close"
- Open the directory where the file or files you intend to password protect are. Create an .htaccess file if none exists.
- Right click the .htaccess file, and select "Code Edit".
- Insert this code into the .htaccess file, remembering to replace "examplefile.extension" with your file's actual name, and replacing cpanelusername with your cPanel username.
"<FilesMatch "examplefile.extension">
AuthName "Member Only"
AuthType Basic
AuthUserFile /home/cpanelusername/.htpasswd
require valid-user
</FilesMatch> - Click "Save Changes"
- Click "Close"
Multiple Files
You can use the "*" as a wildcard in the .htaccess code. In the "<FilesMatch" line, using the star to replace the filename or the file extension will password protect all files with that extension in the folder, or all files of various extensions with the same name.