Password Protecting a Single File

Password Protecting a Single File

  1. Create a file called ".htapasswd" and put it above your root directory. Visitors are unable to access it in this location.
  2. Create an encrypted password. This can be done with a password generator tool, such as htpasswd.
  3. Right click the .htpsddwd file, click "Code Edit".
  4. Click "Edit".
  5. Paste the generated password information into the .htpasswd file.
  6. Click "Save Changes", then "Close"
  7. Open the directory where the file or files you intend to password protect are.  Create an .htaccess file if none exists.
  8. Right click the .htaccess file, and select "Code Edit".
  9. Insert this code into the .htaccess file, remembering to replace "examplefile.extension" with your file's actual name, and replacing cpanelusername with your cPanel username.
    "<FilesMatch "examplefile.extension">
    AuthName "Member Only"
    AuthType Basic
    AuthUserFile /home/cpanelusername/.htpasswd
    require valid-user
    </FilesMatch>
  10. Click "Save Changes"
  11. Click "Close"

Multiple Files

You can use the "*" as a wildcard in the .htaccess code. In the "<FilesMatch" line, using the star to replace the filename or the file extension will password protect all files with that extension in the folder, or all files of various extensions with the same name.

  • 34 Users Found This Useful
Was this answer helpful?

Related Articles

Do you offer password protected directories?

By default, cPanel allows you to password protect directories in your account that you wish to...

Why can't I log into my cpanel or webmail?

There various issues that you may not be able to login to your cPanel or WebMail. We have...

Custom Error Pages

Creating your own error pages can be accomplished through cPanel. After logging in, under...

Requesting a New cPanel Password

Resetting Your cPanel PasswordYou can reset your cPanel password from the cPanel login screen....

Secure cPanel Login

Using Shared SSL to Access cPanel Use https, enter your site's IP address, and the secure port...