1

I tried to implement htaccess password protection for a directory in my localhost.

My htaccess file is situated in /home/Server/Dev. The directory I want to protect is /Dev/. My .htaccess file has the following contents:-

AuthName "Restricted Area" 
AuthType Basic 
AuthUserFile /home/admin/.htpasswd 
AuthGroupFile /dev/null 
require valid-user

My .htpasswd file is situated in /home/admin/.htpasswd and has the following content:-

sparky:19m8GEYhMZvMY

But when I try accessing http://localhost/Dev/, password is not asked and the url is directly accessible. Can anyone please point out what I'm doing wrong.

1 Answer 1

2

This will most likely be because you have an AllowOverride statement that is disallowing access to .htaccess files. You will need to configure as a minimum

AllowOverride AuthConfig 

within a <Directory> block for /home/Server/Dev

<Directory /home/Server/Dev >
    AllowOverride AuthConfig
    ...
</Directory>
3
  • I added AllowOverride AuthConfig to 000-default' within a <Directory> block for /home/Server/Dev`. Now the username-password window is shown, but no matter what I enter, a 500 internal server error page is shown when i click login.
    – Sparky
    Oct 19, 2011 at 12:06
  • 1
    Then you should go and look at your apache error log for more .information
    – user9517
    Oct 19, 2011 at 12:38
  • Whoever finds this online, don't forget to add ErrorDocument 401 "Authorisation Required" because otherwise it will throw you into an endless loop if you don't get the password right Jun 1, 2016 at 8:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .