Jump to content

Recommended Posts

Posted

Hi,

 

I'm trying to setup a custom error page for a 401 error. Here's my .htaccess:

ErrorDocument 404 /notfound.php

ErrorDocument 401 /unauthorized.php

 

The problem is, it doesn't seem to parse php correctly for a 401 error. Note my 404 works fine; the page is displayed properly. However, when my 401 page is displayed, it looks like it's totally ignoring the php. I see the html of the page, so it's finding the page ok, it just isn't parsing the php.

 

Is there some reason why a php page can't be used for a custom 401? Or is there another step I need to do to have the server parse the php properly?

 

Thanks.

Posted

Correct, if I just go to the page straight, it works fine.

 

In fact, the page is an exact duplicate of my 404 page, with slightly different text. The 404 is correctly served, but the 401 is not.

 

It looks like for some reason it does not parse the php properly in the 401 error page, even though it does in the 404.

 

Is there something about the nature of a 401 that causes the php not to be parsed? Perhaps this is an Apache bug?

Posted

Well....looks like I misdiagnosed the problem.

 

I was using php to set the stylesheet based on the browser. When the stylesheet wasn't being invoked properly, I incorrectly assumed the php wasn't working. But really the issue is since I got the 401 by trying to access a subfolder, it looks like I was no longer at the root level, even though my 401 page was located there.

 

Clear as mud, I know. Specifically, a simplified version of my page had this code:

<?php

echo '<link rel="stylesheet" href="styles/sdi3column_allbrowsers.css" type="text/css">';

?>

 

Note that "styles/sdi3column_allbrowsers.css" is assuming I'm at the root level. (My 401 page IS at the root level).

 

If I got the page by calling it, http://www.silverleafdesign.com/unauthorizedtest.php, the page rendered fine. However, if I got the page by going to www.silverleafdesign.com, clicking on Client Login, and then hitting Cancel, the page did not find the stylesheet.

 

However, when I changed the path of the stylesheet in the 401 page to "/styles/sdi3column_allbrowsers.css" (added / to the front), then the page rendered correctly when I got there by trying to log in.

 

Do you know why this would be the case? Logically, since the 401 page is at the root level, I would think that "styles/sdi3column_allbrowsers.css" would work correctly, but it didn't until I add the /. Why would this be?

 

Thanks, Susie

Posted

When I run into problems like that I code it with a full path to the CSS file.

 

><?php 
echo '<link rel="stylesheet" href="http://your-site.ext/styles/sdi3column_allbrowsers.css" type="text/css">';
?>

 

Then the server doesn't have to guess where you are trying to point too.

Posted

Hi,

 

Thanks for the suggestions.

 

The article you mentioned, Jimuni, is referring to using includes. In my case, I'm not using an include, I'm calling a 401 page that is located in the root. Nevertheless, the article states that, for includes, the path is relative to the calling page. If that logic carried over to my 401 page, it should work. Since the 401 page is at the root level, calling a stylesheet from within that page where the path is relative to the root level should work fine.

 

That doesn't explain to me why the path in the 401 page is NOT relative to the location of that page; it is relative to the subfolder I tried to access when the 401 was called.

 

I understand the workarounds to make the path absolute, but I'm still wondering why it behaves this way in the first place.

 

Thanks.

Posted (edited)

Hello,

 

Yes the page is about includes, but the paths for php remain the same, hope it was not too confusing!

 

>"/styles/sdi3column_allbrowsers.css"

 

This is an absolute path, so no matter where you place it, it will always pull that page.

 

If however, you are creating the 401 from a sub folder, e.g.

www.domain.com/subfolder/401.php

 

Even though your pulling the file from the root, the relative path is still www.domain.com/subdfolder/401.php

 

Hence the original

>styles/sdi3column_allbrowsers.css

would not have worked as you it would be looking to pull:

www.domain.com/subdfolder/styles/sdi3column_allbrowsers.css

and you would have needed to have put

>../styles/sdi3column_allbrowsers.css

for the page to work correctley

 

I think anyway! :pissed:

 

Jimuni

Edited by Jimuni
Posted

My 401 page is NOT in a subfolder, it's at the root level. That's my point.

 

www.domain.com/401.php

 

It works fine if you call it straight:

www.domain.com/401.php

 

It doesn't work if it is invoked by trying to access a subfolder that you don't have access to.

Posted (edited)

Hello,

 

Whilst the 401 is at root level, the error page is being called from a subfolder, e.g:

http://www.silverleafdesign.com/clientarea/client.php

 

 

E.g normal error:

http://www.silverleafdesign.com/401.php

 

Subfolder error (ok not correct url but you see what i mean)

http://www.silverleafdesign.com/401.php

 

hence whilst both pages pull and show the same 401 page, the actually path for that page is different because of where its being viewed from, hence the above notes in my previous post.

 

Jimuni

Edited by Jimuni
Posted

Then I'm not quite understanding how a 401 works.

 

Even though it is being called from the subfolder, the page still lives in the root, correct? Isn't the root page being served?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...