I'm trying to add password protection to my personal website using .htpasswd and .htaccess. When I enter the username and password, I get asked again and again. How do I resolve this?


st:((encrypted pw))


AuthUserFile /.htpasswd
AuthGroupFile /dev/null
AuthName "Enter Password"
AuthType Basic
require valid-user

Both files are in the root directory. This is the first website I'm building, so I'm no expert.

Edit: I used this tool to create my .htpasswd file.

AuthUserFile /.htpasswd

Both files are in the root directory.

The AuthUserFile directive takes an absolute filesystem path (or a path that is relative to the server root), not a path relative to the document root - which is what /.htpasswd looks like? It is unlikely that your "root directory" (by which I assume you mean your website's DocumentRoot) is in the root of your server (if it is then you should probably change it).

You'd expect this to be something like:

AuthUserFile /home/user/secure/.htpasswd
| improve this answer | |
  • Thank you, that's a good point. How do I find the absolute path to a given directory? – Stephan Jan 27 '18 at 17:45
  • What sort of server/hosting/control panel (eg. cPanel) and/or server-side scripting language are you using? If you know the document root then you can work it out. Ideally, .htpasswd files should be stored above the document root (although they often default to being stored in the same directory as the .htaccess file). – MrWhite Jan 27 '18 at 17:56
  • 1
    That was the problem: I didn't know my document root. But I've found a way to find it out (stackoverflow.com/questions/6079479/…) and now it works! Thank you so much for the hint! – Stephan Jan 27 '18 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.