Password Protect One File

Cant I log into my cPanel WHM or webmail
August 8, 2012
Path to an addon domain
August 12, 2012

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/.htpassw

  2. Put the username and encrypted password inside the .htpasswd file. EXAMPLE:

    username:n5MfEoHOIQkKg

    To create the encrypted password you will need to use a utility such as the command-line program htpasswd.

    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