cancel
Showing results for 
Search instead for 
Did you mean: 

.htaccess

xpher
Grafter
Posts: 58
Registered: ‎02-08-2007

.htaccess

Hi
Have htaccess to password protect a sub directory. What i want to do is set it up so that if someone clicks cancel on password dialog it redirects to a file in higher directory which I've called main_dir in below example. This is my htaccess file

AuthName "members"
AuthType Basic
AuthUserFile /files/home2/user/main_dir/protected/.htpasswd
require valid-user
ErrorDocument 401 ../index.html
I get the user/password dialog OK and can login but all I get for the 401 error document (if cancel) is a page that prints ../index.html
Any pointers as to where I'm going wrong?
5 REPLIES
xpher
Grafter
Posts: 58
Registered: ‎02-08-2007

Re: .htaccess

Intersting that if I replace the ../index.html with html it works
i.e. ErrorDocument 401 "<a href='../index.html'>Click</a>"
prichardson
Grafter
Posts: 1,503
Thanks: 1
Registered: ‎05-04-2007

Re: .htaccess

The ErrorDocument directoive does not accept relative paths.
If the file provided does not conform to URL standards 9ie, not a full external URL, or not a path starting /), it will treat the item as text.
So if for example your protected file is in http://ccgi.username.plus.com/main_dir/protected/
And you wanted the file you provided, you would supply
ErrorDocument 401 /main_dir/index.html
xpher
Grafter
Posts: 58
Registered: ‎02-08-2007

Re: .htaccess

Thought I'd tried that. But yes that works thanks. The interesting thing is when the error document loads it doesn't load the external css file so it just shows page without CSS. Not a problem but wondered why?
Community Veteran
Posts: 14,469
Registered: ‎30-07-2007

Re: .htaccess

Where is the CSS file in relation to the error document file?
Are you using a relative (i.e. ../styles/style.css) path to it or an absolute (/styles/style.css) path to it. Try either method to see if it is loaded.
xpher
Grafter
Posts: 58
Registered: ‎02-08-2007

Re: .htaccess

The problem is I think its looking for CSS that is in protected directory eventhough loading page from above. No worries it's not a problem, I've done things slightly different which is improved.