How to Password Protect one file

1) Put your .htpasswd above your root so visitors can't access it
/home/cpanelusername/.htpasswd

2) Put the username and encrypted password inside the .htpasswd file.
john:n5MfEoHOIQkKg
To create the encrypted password, use an online utility, such as http://home.flash.net/cgi-bin/pw.pl

It doesn't matter how many files under how many directories you wanted to protect, they can share a common .htpasswd file.

3) Place the following code in your .htaccess file, in the same folder where you want to protect the file. (Be sure to replace cpanelusername with your actual cPanel username. Replace test with the path to your file. Replace file.html with your file's actual name.)

/home/cpanelusername/public_html/test/.htaccess
<FilesMatch "file.html">
AuthName "Member Only"
AuthType Basic
AuthUserFile /home/cpanelusername/.htpasswd
require valid-user
</FilesMatch>
/home/cpanelusername/public_html/test/file.html is protected
/home/cpanelusername/public_html/test/index.html and all others are NOT protected

You can protect more than one file by using wildcard names. On the FilesMatch line, follow one of these examples:
<FilesMatch "*.html">
<FilesMatch "file.*">
<FilesMatch "*.*">

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to create/edit/delete a file using the File Manager

There may be times when you wish to create, edit, or delete a file or folder in your account....

How to upload a file using the File Manager

You may want to upload your files directly through cPanel. You can do this through the File...

How to navigate through File Manager

How to navigate through File Manager File Manager is an quick and easy way to navigate through...

How do I create a MySQL database, user, and then delete if needed?

Create: If you are using any type of PHP software or keeping a collection of records which need...

How to park a domain on an addon domain

cPanel has yet to offer this option although it can be done. In order to park a domain on...