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

AuthName "Member Only"
AuthType Basic
AuthUserFile /home/cpanelusername/.htpasswd
require valid-user

/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: 

  • Email, SSL
  • 10000 Users Found This Useful
Was this answer helpful?

Related Articles

Accessing Web Disk

Web disk (also known as Web Dav) is a drag-and-drop interface which allows you to access your...

Apache Error Logs

When you check the error logs, you can see many things.Some things you can ignore:File does not...

Apache modules that are on all of our shared servers

core.c mod_authn_file.c mod_authn_dbm.c mod_authn_dbd.c mod_authn_default.c mod_authn_alias.c...

Can I password protect directories?

To password protect directory: Wait! Why read this when you can watch the movie tutorial...

CGI center

The following CGI Scripts are pre-installed and ready to use on your account: Simple CGI Wrapper...