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.

Sparky
  • 213
  • 2
  • 6
  • 12

1 Answers1

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>
user9517
  • 114,104
  • 20
  • 206
  • 289
  • I added `AllowOverride AuthConfig` to `000-default' within a 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 '11 at 12:06
  • 1
    Then you should go and look at your apache error log for more .information – user9517 Oct 19 '11 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 – mehov Jun 01 '16 at 08:37