HostMonster Web Hosting Help

Password Protect a File

Summary

The easiest method of password protecting a single file on your hosting account is to first password protect the directory which contains that file. This can be done using the Password Protect Directory tool in your cPanel.

This article will show you how to manually password protect a directory (folder) on your account.

Password Protect a Directory

When you Password Protect a directory, the system will place configurations into a file called '.htaccess'. This file will be located in the folder that you protected.

In the .htaccess file will be statements such as the following:

    AuthType Basic
            AuthName "Restricted Area"
            AuthUserFile "/home/[username]/.htpasswds/public_html/passwd"
            require valid-user

You will now need to modify the .htaccess file so that it applies the statements to a specific file. This is done with the following tags:

    <Files [filename]></Files >
            

In this example, we will protect the file 'secure.html'. This is done by modifying the .htaccess statement as follows:

    <Files secure.html>
              AuthType Basic
              AuthName "Restricted Area"
              AuthUserFile "/home/[username]/.htpasswds/public_html/passwd"
              require valid-user
            </Files>

This can also be used to protect multiple individual files in directory, the method is very similar, however this time use Apache’s FilesMatch directive. This allows us to list as many files as needed:

    <FilesMatch "(secure\.html)|(secure\.txt)">
              AuthType Basic
              AuthName "Restricted Area"
              AuthUserFile "/home/[username]/.htpasswds/public_html/passwd"
              Require valid-user
            </FilesMatch>

Note: To add files, include more instances of “|(filename\.ext)”.

Knowledgebase Article 103,978 views bookmark tags: file passwd password prompt protect secure single (updated 1001 days ago)


Was this resource helpful?

Did this resolve your issue?


Please add any other comments or suggestions about this content:





Recommended Help Content

This tutorial will show you how you can password protect parts of your website by password protecting the folder(s) on your account. (updated 205 days ago)
Video "How-to" Tutorial 122,776 views tags: cpanel cpanelutilities login password protect

How do I password protect a folder on my website? (updated 205 days ago)
Knowledgebase Article 89,960 views tags: folder password protect

What should I do if I am having problems with multiple password prompts on my password protected directory? (updated 2027 days ago)
Knowledgebase Article 79,557 views tags: folder password protect

Related Help Content

How do I change my Control Panel password? (updated 907 days ago)
Knowledgebase Article 136,207 views tags: change cpanel password passwords protect

How can I protect the images on my website? (updated 1356 days ago)
Knowledgebase Article 127,777 views tags: click code image images javascript protect save saving script tips tricks

How do I use a secure FTP connection? (updated 870 days ago)
Knowledgebase Article 134,177 views tags: ftp secure sftp shell ssh

This article will explain how to change the password for a database in the event that the original password is lost. (updated 821 days ago)
Knowledgebase Article 27,098 views tags: database mysql password

This article explains the different password types for your hostmonster account. (updated 11 days ago)
Knowledgebase Article 334 views tags: billing cpanel hosting main password

When FAQMasterFlex is installed in a subdirectory on an account and the administrator tries to login to the faq_admin.php page, the program will not accept the administrator username and password. (updated 1618 days ago)
Knowledgebase Article 48,340 views tags: password

I am prompted to set a new MySQL password. What does this mean and how do I change it? (updated 968 days ago)
Knowledgebase Article 64,173 views tags: connect database mysql password phpmyadmin username

When you try to use HostMonster.com over a secure form it will tell you that email it sends will not be encrypted. (Happens more often with Firefox) (updated 2025 days ago)
Knowledgebase Article 61,523 views tags: form secure