Small .htaccess problem

My boss asked me this morning to password protect a site directory. No problem. The site is located at http://www.root.com/sitedirectory

So I set up my .htaccess:


AuthUserFile /home/user/.htpasswd
AuthType Basic
AuthName "Secret!"
Require valid-user

And my .htpasswd:


user:encrytpedpass

The .htpasswd is in the root directory. The .htaccess is in the sitedirectory folder.

When you visit the url, the prompt comes up and asks you for the user/pass. But when I ented them, it asks again. So, clearly something got messed up, but I can’t think of what it could possibly be. Anyone?

Sorry if any of these questions sound patronizing, not my intent;

Do you have multiple .htaccess files in root/child directories to ‘sitedirectory’ that also contains an authtype?
Do you have any redirects or header locations inside ‘sitedirectory’ files?
Does your apache follow symlinks?

Oh, it’s good habit to tell apache that there’s no group file;


AuthGroupFile /dev/null

And it’s also very good practice to keep your .htpasswd file in the same folder as the .htaccess file when you nest them in directories like that. So your .htpasswd should get redone and located in /home/user/sitedirectory/

Apart from that, not sure :x

I have one. There’s a form that redirects to another page after the submit button is clicked.

after you put it in the second time does it allow you to enter?

oh wait I think I know what it is.

Make sure you add a trailing slash to the directory when you access it;

ie: www.site.com/directory (WRONG)
www.site.com/directory/ (RIGHT)

Add a rewrite rule to direct users from the Wrong one to the right one. Should sort your problem.

I fixed it. I’m a retard. Something in the path was missing.