Bluehost Web Hosting Help
Password Protect a File
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)”.
Recommended Help Content
How do I password protect folders?
This tutorial will show you how you can password protect parts of your website by password protecting the folder(s) on your account. (updated 147 days ago)
Password Protect a folder on your website
How do I password protect a folder on my website? (updated 148 days ago)
Password Protected Folder Gives Continual Prompts
What should I do if I am having problems with multiple password prompts on my password protected directory? (updated 1969 days ago)
Related Help Content
How to Reset your Control Panel password
How do I change my Control Panel password? (updated 850 days ago)
Right-Click Image Protection
How can I protect the images on my website? (updated 1298 days ago)
FTP setup using Secure FTP (SFTP)
How do I use a secure FTP connection? (updated 812 days ago)
Resetting MySQL Database User and Password
This article will explain how to change the password for a database in the event that the original password is lost. (updated 762 days ago)
FAQMasterFlex administrator password not working
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 1560 days ago)
Setting a Password for the Main MySQL User
I am prompted to set a new MySQL password. What does this mean and how do I change it? (updated 910 days ago)
BlueHost.com HTTPS Security Error
When you try to use BlueHost.com over a secure form it will tell you that email it sends will not be encrypted. (Happens more often with Firefox) (updated 1967 days ago)
Resetting the Password for an Email Account
Instructions for restting your Email Account's Password through cPanel or Webmail (updated 763 days ago)