How to password protect one file ?

 

This is an advanced design tutorial. If you are a beginner, we recommend using the cPanel Password Protect Directory icon. That icon can only protect all the files in a folder, not one specific file.

  1. Create a file named .htpasswd and place it above your root so visitors can't access it.
    EXAMPLE: /home/cpanelusername/.htpasswd
  2. Put the username and encrypted password inside the .htpasswd file. EXAMPLE:
    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.)

    EXAMPLE: /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 "*.*">

 

  • 1 Users Found This Useful
Was this answer helpful?

Related Articles

Apache Error Logs

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

Accessing Web Disk

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

Apache Handlers (running html as php)

Apache handlers allow you to control what Apache will do with certain file types. When Apache...

Backup File Types

So, you have a backup file, but you need to know what type of backup it is so you can know what...

Copy Entire Database or Rename Database

Is there a way for me to copy an entire database in cPanel from another server? You will need...