How to Password Protect One File

Follow

To password protect an individual file:

Log into your cPanel and click on File Manager. Choose to go to the Home Directory, click show hidden files and then Go

Create a file named .htpasswd and place it in the home directory, so visitors can't access it.

Note: It doesn't matter how many individual files you wish to protect; they can all share a common .htpasswd file.

Right click on the .htpasswd file and select the Code Edit option.

In the popup that appears, click the Edit button.

Generate a username and password for the protected files. There are websites that can make these for you, for example: http://www.htaccesstools.com/htpasswd-generator

Place the generated .htpasswd information into the .htpasswd file.

Click on the Save Changes button.

Click on the Close button.

Now find the files that need protecting.

Navigate to the directory where the file(s) that you would like to password protect lie.

If an .htaccess file does not exist in the directory already, create one.

Right click on the .htaccess file and select the Code Edit option.

Insert the following code into the .htaccess file:

<FilesMatch "Protected file">
AuthName "Member Only"
AuthType Basic
AuthUserFile /home/cPanelusername/.htpasswd
require valid-user
</FilesMatch>

Be sure to replace Protected file with your file's actual name and replace cPanelusername with your actual cPanel username.

Click on the Save Changes button.

Click on the Close button.

This will protect the specified file, while leaving all other files in the folder available.

Note: You can protect more than one file by using wildcard names. On the FilesMatch line you can use one of the directives below:

<FilesMatch "*.html">

<FilesMatch "file.*">

<FilesMatch "*.*">

Have more questions? Submit a request

Comments

Powered by Zendesk