This is a discussion on htaccess: ErrorDocument & Authorization (Apache) within the Linux Web Servers forums, part of the Web Server and Related Forums category; I've got a directory setup that looks like this: /Public .htaccess public.shtml /Private .htaccess .htpasswd private.shtml /Public/....
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I've got a directory setup that looks like this:
/Public .htaccess public.shtml /Private .htaccess .htpasswd private.shtml /Public/.htaccess looks like: ErrorDocument 401 /Public/public.shtml /Public/Private/.htaccess looks like: AuthName "section" AuthType Basic AuthUserFile /Public/Private/.htpasswd Require valid-user So, if I enter: http://domain.com/Public/Private/private.html it my browser, I see in the access log a 401 response code and the authorization dialog appears. If I press the cancel buton, the authorization dialog appears again and I press the cancel button again. At this point, the ErrorDocument appears, but the URL in the browser still shows: http://domain.com/Public/Private/private.shtml If I do not specify an ErrorDocument, after I press the cancel button for the first time, the URL in the browser shows: http://domain.com/Public/Private/private.shtml I do not get two authorization dialogs and the default apache error page shows. What I would like to have happen is for the browser to be redirected to: http://domain.com/Public/public.shtml after the cancel button is pressed the first time. Any hints on how to make this happen? |
|
|||
|
Well, after playing around with this some more, I found a solution which
I believe to be acceptable. The ErrorDocument now points to a .html document which has the following basic form (a couple of details removed): <html> <head> <title>Not Authorized</title> <meta http-equiv="Refresh" content="15; URL=/Public/notauthorized.html"> </head> <body bgcolor="#FFFFFF"> <p>I'm sorry, but a valid username and password was not entered. The browser will now be redirected back to the main downloads page where a request can be made for a valid username and password. If the browser is not redirected within a few seconds, please click on the link below. </p> </body> </html> Basically, it just brings up an error pages which let's the user know what happened and then redirects the user back to a page they are allowed to access after 15 seconds. A solution I had tried before what to point ErrorDocument at a page that looked like: <?PHP header( "Location: /Public/public.shtml"); ?> but this just resulted in the redirect taking place immediately before the user was allowed to enter a name and password. Edit/Delete Message |