Apache: Protect just one file in a directory by password

Hi,

these are the steps to protect a single file in a directoy by a password.

For example: The folder /var/www/html is and the file you want protect is called internal.html

Define a username (here “agent”) and create a password file (.htuser)
root@debdevt # htpasswd -c -B /var/www/html/.htuser agent

create a .htaccess file in the folder /var/www/html with content:

<FilesMatch "internal.html">
AuthName "Only for Agents"
AuthType Basic
AuthUserFile /var/www/html/.htuser
require user agent
</FilesMatch>

 

Note:The AuthUserFile must contain the absolute path to the .htuser file.

That’s it 🙂

Michael

Advertisment to support michlstechblog.info

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.