Forum Moderators: phranque

Message Too Old, No Replies

Troubleshooting .htaccess - Password Protect Directory

         

aHart

9:59 pm on Jan 21, 2008 (gmt 0)

10+ Year Member



This is the first time I've really dealt with having to password protect a specific directory, and I am having a problem with what should be (according to my research) fairly simple functionality.

I have a specific directory inside of public_html called restricted. In restricted, I have placed a zipped file containing some marketing materials for my company (there are no other files here).

The directory, restricted, is password protected using the cPanel (which has just created the .htaccess file and passwd file for me). There is only one username currently. This is the only directory that is password protected.

When you visit the site, head to the "Support" area, and the click on the link to "Logos & Identity", you are taken to a page in public_html which has information about obtaining the username and password for restricted.

On the logo page, there is a link to download the zipped file that has been placed inside of the restricted directory. When you click on the link, it prompts the user for a username and password.

If you have the correct username and password, you are given the dialog box to download the zipped file. Works perfectly.

If you do not, however, have the username and password, the alert box will NOT go away. You cannot click cancel, you cannot close it, you are not taken to a "403 Forbidden" or any other error page. Nothing. It is annoying and the alert box will not go away. You actually have to force quit your browser.

This is a huge problem and I cannot for the life of me figure out how to solve it.

This is the contents of my .htaccess file for the restricted directory:


AuthType Basic
AuthName "Waterway Logo Download"
AuthUserFile "/home/waterboy/.htpasswds/public_html/restricted/passwd"
require valid-user
Options All -Indexes

The URL for the website is:
<snip>
(menu "Support" --> "Logo & Identity" --> click on the link to download)

Any help would be greatly appreciated! Thank you!

[edited by: jdMorgan at 10:09 pm (utc) on Jan. 21, 2008]
[edit reason] No URLs, please. See TOS. [/edit]

jdMorgan

10:10 pm on Jan 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you use custom error pages? If so, what is the URL-path defined for "ErrorDocument 401"?

Jim

aHart

10:14 pm on Jan 21, 2008 (gmt 0)

10+ Year Member



Hi Jim--

Yes, we do have custom error pages.

Right now, they are located in public_html. So, the 401 error is:

/home/waterboy/public_html/401.shtml

or

[ourdomainhere.com...]

(edited out the domain name, since I saw you snipped it before :))

(oops, sorry about that-- typo above that I've fixed.)

[edited by: aHart at 10:15 pm (utc) on Jan. 21, 2008]

jdMorgan

10:22 pm on Jan 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



May we see the actual ErrorDocument 401 directive, please?

The "got stuck" problem hints that the path to the 401 errordocument may be resolving to the protected directory, so that the 401 auth failure basically 'loops' in that protected directory, and you can't get out.

Jim

aHart

10:30 pm on Jan 21, 2008 (gmt 0)

10+ Year Member



Ah, that would make sense. And I think it might actually be my problem.

As far as I can tell, right now, there is no mention of ErrorDocument in any .htaccess file (obviously running into a problem for the restricted directory).

Am I right in thinking I will need to add:

ErrorDocument 401 ../401.shtml

to the .htaccess file inside of restricted?

jdMorgan

10:58 pm on Jan 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You should not have to *add* anything -- except to correct some bad code elsewhere, such as in your http.conf file or in .htaccess files above the directory in question.

I suppose you could try it as a "proof of concept" like this, with a server-rooted local URL-path (required):


ErrorDocument 401 /401.shtml

Also, do be sure that since 401.shtml is dynamic, it does not reference any objects in the protected directory.

Jim