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 control panel.

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. This would be done as follows:

<Files secure.html stillsecure.html secret.php members.shtml>

AuthType Basic

AuthName "Restricted Area"

AuthUserFile "/home/[username]/.htpasswds/public_html/passwd"

require valid-user

</Files>

  • 0 brukere syntes dette svaret var til hjelp
Var dette svaret til hjelp?

Se også:

How do I password protect a folder on my website?

Do not follow the steps below if you are using frontpage extensions on your site. Doing so will...

Code behind the protection (.htaccess) Hotlink protection

Problem: I need to protect the /images folder to not show images when people type in the correct...

Why don't my images display on my site?

If the images are uploaded in the correct location and your code references each image correctly,...

Hot Link Protection

Setup of Hot Link Protection 1. Log into cPanel 2. Go to Hot Link Protection Fields URLs to...

How do I create a PGP certificate?

First you will need to go to the File Manager and create a folder with the name of .gnupg in the...