adding .htaccess and .htpasswd files do not restrict access to localhost folder - .htaccess

I have followed the procedure to the letter and it does not work for me.
The procedure: Create file .htaccess which has the following lines of text.
AuthType Basic
AuthName "restricted area"
AuthUserFile "C:/Apache24/htdocs/protected/.htpasswd"
require valid-user
Next create file .htpasswd which has a username and encrypted password created by http://www.htaccesstools.com/htpasswd-generator/
Next I insert both .ht files into the folder named protected, which is in the folder htdocs.
When I type in the browser address window http://localhost/protected/ and hit enter I get Index of protected and the list of files in it. It never asks for username or password.
See summary above.
AuthType Basic
AuthName "restricted area"
AuthUserFile "C:/Apache24/htdocs/protected/.htpasswd"
require valid-user

Related

.htaccess/.htpasswd not working on web host

I have my website setup on a web host. My .htaccess and .htpasswd files are not working. The alert pops up but it keeps asking for the username and password even though I input the correct credentials.
The directory of these files is:
/home8/afmaclub/public_html/Members/.htaccess
/home8/afmaclub/public_html/Members/.htpasswd
The code for the .htaccess and .htpasswd is below:
.htaccess
AuthName "Member\'s Area"
AuthUserFile /home/afmaclub/public_html/Members/.htpasswd
AuthGroupFile /dev/null
AuthType Basic
require valid-user
.htpasswd
Username:Encrypted Password

.htaccess password on root not working

i'm trying to apply a site password to the root directory of my site:
www.example.com
I have my .htpasswd file in the same directory as the .htaccess file (public_html) and my .htaccess file has the following code:
AuthType Basic
AuthName "This Area is Password Protected"
AuthUserFile /public_html/.htpasswd
Require valid-user
With this code it prompts for credentials however when I enter the correct credentials it takes me to a server error page. Where have I gone wrong here?

Variable in Path to .htpasswd file in .htaccess

Would it be possible to have the {HTTP_HOST} variable in this path?
Because my htaccess is used for multiple domains and I want to use different passwords for each domain!
AuthUserFile /usr/test/{HTTP_HOST}/.htpasswd
AuthType Basic
AuthName "My Files"
Require valid-user
UPDATE:
I tested the above code and it gives a 500 Internal Server Error (off course the AuthUserFile points to a directory that DOES exist on my server)

htaccess different user permissions for different users

I can't seem to find the proper way to write my .htaccess file. I initially had the file set up to allow access to a directory of files and that worked fine:
AuthUserFile /var/www/html/technical/mep/.htpasswd
AuthGroupFile /dev/null
AuthName "Password Protected Area"
AuthType Basic
Require valid-user
Now what I need to do is add an additional htpasswd file (something like .htpasswd2) and allow those additional user to only be able to access a single file in that directory. How do I edit my current .htaccess file to make this happen?
You can simply use the <FilesMatch> container:
<FilesMatch protected.html>
AuthUserFile /var/www/html/technical/mep/.htpasswd2
AuthGroupFile /dev/null
AuthName "Password Protected Area 2"
AuthType Basic
Require valid-user
</FilesMatch>
And the file "protected.html" would use the .htpasswd2 file.

Referencing .htpasswd from accounts with different usernames

I push my website to multiple servers where I have different usernames. I want to have a .htaccess file that password protects a file regardless of which server I'm on.
The issue is that AuthUserFile only takes absolute paths, so if I have:
AuthUserFile /home/will/.htpasswd
I get a server error on a box where my username is wjholcomb (and home directory is /home/wjholcomb/).
.htaccess can have multiple AuthUserFile lines:
AuthUserFile /home/will/.htpasswd
AuthUserFile /home/wjholcomb/.htpasswd

Resources