I have a .htpasswd file I created in my home directory, and an existing .htaccess file for all of my site pages. I am trying to password protect only one of these pages.
I tried grouping a new .htaccess file with the file/page I am trying to protect in a subfolder / subdirectory, but the pages start to malfunction (maybe because I used a website builder?).
When I add only the code below into the .htaccess file for the entire website without any more commands, the password protection works / functions properly with the right username/password, but the entire site is password guarded. I am unsure how to target only the one file/webpage rather than targeting my entire website! I have tried a couple different commands such as Location, Files, FilesMatch, but the password protection disappears entirely when I use them.
AuthType Basic
AuthName "Please Log In"
AuthUserFile /home/usrname/.htpasswd
require valid-user
Anything else I can try?
This probably is what you are looking for:
Note that you need to specify an absolute path to the ".htpasswd" file. And that this file should be stored outside the
DOCUMENT_ROOTlocation inside the file system for security reasons.