htaccess problem

Joined
12 Feb 2006
Posts
17,672
Location
Surrey
i'm trying to protect a directory by adding htaccess username and password verification.

i uploaded and it asked for username/password so thought i'd test by trying wrong details. i then got a 500 internal error and that's all i get now which is a pain as i'd like to try again.

any thing i'm doing wrong?

this is what i have...

.htaccess file

Code:
AuthType Basic
AuthName "This is a protected area"
AuthUserFile /home/xyz/public_html/php/upload
Require valid-user

.htpasswd file
Code:
admin:OdfRyggFdf2Z/gI
 
Can you view what the error is in the log file? If you have cpanel I think there's an option to view it.

Alternatively you could try this.
 
error log.

[Thu Sep 02 20:34:13 2010] [error] [client 86.16.135.182] File does not exist: /home/xyz/public_html/500.shtml
[Thu Sep 02 20:34:13 2010] [error] [client 86.16.135.182] (9)Bad file descriptor: Could not open password file: /home/xyz/public_html/php/upload
[Thu Sep 02 20:34:13 2010] [error] Access to file /home/xyz/public_html/php/upload denied by server: not a regular file

htpasswd generator is what i used :p
 
The AuthUserFile should point to the path of the .htpasswd file, so if you placed it in public_html/php/upload you would use:

PHP:
AuthType Basic
AuthName "This is a protected area"
AuthUserFile /home/xyz/public_html/php/upload/.htpasswd
Require valid-user

Are you changing /home/xyz to the actual path of your account on the server?
 
The AuthUserFile should point to the path of the .htpasswd file, so if you placed it in public_html/php/upload you would use:

PHP:
AuthType Basic
AuthName "This is a protected area"
AuthUserFile /home/xyz/public_html/php/upload/.htpasswd
Require valid-user

Are you changing /home/xyz to the actual path of your account on the server?

the only part i'm changing is the xyz part, /home is there as it should be, or am i wrong?

what weird is whilst the htaccess file is there when i'm in folder php i can't see php folder, although i can access it by manually adding it to the url, but then when i remove the htaccess file i can now find the folder again and view it fine. if i then re-add the htaccess file and refresh i can continue accessing the folder and viewing it from php with no attempt of logging
 
Last edited:
Did you change it like I posted above, where it links to .htpasswd too?

What does it say in the error log if you do that?
 
maybe it's letting me in now for some reason not sure but i think adding .htpasswd has helped.

i don't get asked anything now, though i did once today about 3 hours ago and i entered the correct info but it then showed same error after, but in the latest error logs there is

[Thu Sep 02 23:50:48 2010] [error] [client 86.16.135.182] client denied by server configuration: /home/xyz/public_html/php/upload/.htpasswd, referer: http://www.mysite.co.uk/php/
[Thu Sep 02 23:50:48 2010] [error] [client 86.16.135.182] client denied by server configuration: /home/xyz/public_html/php/upload/.htaccess, referer: http://www.mysite.co.uk/php/
 
Maybe I'm missing which folder you want to protect. If you want to product the root of the PHP folder then move the .htaccess and .htpasswd there (which I assume are currently in the upload folder) and then modify the .htaccess' AuthUserFile to:

AuthUserFile /home/xyz/public_html/php/.htpasswd
 
Ah ok. Well, assuming it's the same site as the one in your sig I get a password prompt when I try and access the upload folder - and filling in random data doesn't let me in, so it all appears to be fine?
 
hmm maybe it's working now but i am let in every time i try to access it but then as i said i did try putting in correct details yesterday when it finally did ask me to login. i think adding the .htpasswd as you suggested perhaps did it.
 
It won't prompt you every time, your browser will remember those details for so long and let you back in.

Try it on a different browser and try clearing your cookies in-between login attempts and it should ask you again.
 
Back
Top Bottom