Forum Moderators: open

Message Too Old, No Replies

http 404

How does one set a personalized 404 page?

         

nvision

11:34 pm on Oct 30, 2001 (gmt 0)

10+ Year Member



Hi there, quick question - how would I set a new 404 page to show up instead of the default pages that come up?

stuart

1:05 am on Oct 31, 2001 (gmt 0)

10+ Year Member



I use an html file called 404.html, designed in the sites general design and do a 10 second redirect to the homepage, its just uploaded to the root/public directory and seems to work okay. Theres probably more advanced methods though!

Xoc

1:59 am on Oct 31, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What web server?

Hunter

2:28 am on Oct 31, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



nvision,

This is copied from a newsletter:

The 404 Page Fix

The best 404 pages explain that the specific information they
were looking for no longer exists, but then offer them several
links into the other sections of your site.

Once you've developed a custom 404 page (which is just a basic
html page), name it "custom_page.html" and upload it to your
server. Then, locate the .htaccess file on your server. It's
located in different places, depending on your server software
and operating system, but it will be there somewhere.

Edit this file so that it contains the following one line command:

ErrorDocument 404 [yoursite.com...]

Obviously, you'll need to change "yoursite.com" to your real
URL.

nvision

11:50 am on Oct 31, 2001 (gmt 0)

10+ Year Member



...this is like the elves that work in the shoe shop when the shoemaker's asleep :) Thanks guys, will work on it. It's a Cobalt server Xoc.

tilt

6:01 pm on Nov 5, 2001 (gmt 0)

10+ Year Member



In my custom 404 page I'd like to include the name of the page that the user is looking for. In other words what page generated the 404?

I'd like my custom 404 to say something like "you're looking for <foobar.html>. This does not exist...."

What's the variable name that will have the name of the referring file?

thanks!

bobriggs

7:32 pm on Nov 5, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



tilt:

On apache:

File requested is: REQUEST_URI
Referer is: HTTP_REFERER

You're looking for <!--#echo var="REQUEST_URI"-->. This does not exist...

tilt

3:05 am on Nov 6, 2001 (gmt 0)

10+ Year Member



bobriggs, thanks for the reply. For some reason, I'm having trouble. If I use REQUEST_URI, my error message displays the name of my custom 404 file, not the name of the missing file that the user tried to find. If I use HTTP_REFERRER, it resolves to "(none)" in my error message.

Anyone know what I'm doing wrong?

Thanks!

bobriggs

2:01 pm on Nov 6, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



tilt:

Well I setup a test and I think I might know what the problem is.

If you've set up .htaccess as Hunter says, you might get the name of the 404doc in REQUEST_URI.

My 404 doc is called missing.html - SSI enabled on .html docs.

I tried it 2 ways, one with the absolute path - and I got the same result you did. The second method was to refer to a local path (/missing.html)

ErrorDocument 404 /missing.html

This got the original requested document in REQUEST_URI and it works.

HTTP_REFERER will only have a value if the user clicked on a link somewhere to get to the page (and then sometimes it will still be blank as in the case of Opera where you can turn off Referer strings).

[added]
See the notes here:
ErrorDocument [httpd.apache.org]

A fully qualified url (with http:// in front) will cause a server redirect to the 404 document, even if it is on the same server, which is not what you want.

tilt

5:39 pm on Nov 6, 2001 (gmt 0)

10+ Year Member



bobriggs,
Thanks for your help. That did the trick.

I didn't understand your reference to missing.html being ssi enabled. I can only get it to work if I use the .shtml extension.

I also uncovered a bug in my custom_404 page. I have links on my page and a message inviting the user to click on a link. However, my links were relative, <a href="clickme.html"> ...

So if a user looked for mypage/images/foobar.fuzzbah, when they got the error, the link was for mypage/images/clickme.html which doesn't exist. There's no way out!

So the solution is to make my links absolute <a href="/clickme.html"> (preceded by a slash). Is that absolute, or relative to home?

Anyhow, thanks again for your help. :)