Forum Moderators: phranque

Message Too Old, No Replies

What is the 'proper' way to implement a custom 404 page?

just curious...

         

ZydoSEO

5:31 pm on Sep 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I know lots of people handle 404s differently. Is there really a 'correct' way to handle 404s? My post is mainly concerned with the interaction between the browser and web server, not the messaging on the page itself.

Currently we are a MS shop running our web server farm on IIS. Our web servers have a custom 404 page defined via IIS. The custom 404 page puts up messaging to let the user know they have requested a page that does not exist with links back to our site (basically the standard global nav and footers) and returns a 404 status. Below is how the interaction between the browser and web server currently works:

1) Browser requests a page that does not exist (http://www.example.com/badpagename.asp).
2) IIS determins the page does not exist and returns a 302 status to the browser indicating that the page was temporarily moved to http://www.example.com/unknown/404.asp?404;http://www.example.com/badpagename.asp which is our custom 404 page. This is handled totally by IIS . IIS automatically adds the '?404;http://www.example.com/badpagename.asp' to the URL of a custom 404 by default.
3) Browser follows the temporary redirect and requests the custom 404 page at http://www.example.com/unknown/404.asp?404;http://www.example.com/badpagename.asp
4) Web server displays the custom 404 page and returns a 404 status to the browser.

Is this the proper interaction between browser and server for a custom 404 page? It just doesn't seen correct to me that the browser address bar (because it was a 302 redirect) has the URL of the custom 404 page in it when it gets the status 404. Maybe I'm wrong but if I were a browser I would interpret that as meaning the custom 404 page does not exist.

The following seems like a more 'proper' implementation of a custom 404 page:

1) Browser requests a page that does not exist (http://www.example.com/badpagename.asp).
2) IIS determines the page does not exist, perform a URL rewrite so that the HTML returned is from the custom 404 page (without redirecting), and returns a 404 status to the browser instructing it that the original page that was requested does not exist.

This way the browser address bar has in it the original bad URL when the 404 status is returned.

Or is the first method correct because the browsers and search engines see the target of the 302 as if it were the original page that was requested even since it has been 'temporarily' moved?

Just curious how others handle their 404s.

jdMorgan

6:12 pm on Sep 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A request for a page that does not exist should result in a direct 404-Not Found server response code, along with whatever content you wish to serve for that error.

Serving a 302 redirect is incorrect.

I'm not sure about IIS, but a common error on Apache servers is to specify a full URL for the error page, i.e. http://www.example.com/404error.php or similar. If a full URL is specified, Apache does not check to see if that URL is actually located on the same site, it simply issues a 302 redirect to that URL.

So, on Apache, the path to the custom error page should be specified only as a local path, relative to server root, i.e. /404error.php

I suspect a similar problem on your site, as I can't believe that IIS would 'get it wrong' under all circumstances -- The hue and cry would be deafening (and would have happened long ago, and would have resulted in a quick fix). So there is likely to be a configuration error or some little 'trick problem' like this one that happens with Apache when a full erro page URL is specified.

Jim

ZydoSEO

7:02 pm on Sep 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I thought that our IIS was handling this incorrectly. I will check into your suggestions. It sounds like it may be similar to the Apache error.

Thanks Jim! You're always a great help.

bwnbwn

7:19 pm on Sep 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I set it up by the book on IIS but got the same response you are getting. I had to add a smal line of asp code on my 404 page to render it a 404 without any redirect.

I had to make the custom 404 page an asp page then point the custom 404 page set up in IIS to the 404.asp page.

Works fine.
<%
Response.Status = "404 Not Found"
%>

Whey this isnt told in the IIS help is not know but this was a sure fix for me.

ZydoSEO

8:34 pm on Sep 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmmm IIS is doing the 302 redirect, not the custom 404 page. IIS redirects the browser to the 404 page. My 404 page already returns the 404 status like you show above. I have that exact code at the top of my 404.asp file:

<%
Response.Status = "404 Not Found"
%>

So my error page is returning a 404 status which is correct (if the original URL were still in the browser address bar). Prior to adding the above line it was returning a 200. If I could just make IIS do a URL rewrite of the requested URL to my custom 404 page rather than 302 redirecting the user to my 404.asp... then life would be good.

I thought Jim Morgan might be on to something, so I checked one of our web servers. IIS is already configured with a root relative custom 404 URL, not a fully qualified URL. So it doesn't appear to be a problem similar to the Apache configuration error he mentioned.

[edited by: ZydoSEO at 8:56 pm (utc) on Sep. 24, 2008]

bwnbwn

9:44 pm on Sep 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



U have to have the set up incorrect in IIS then as it should be throwing a correct 404 when checked if it was set up.

So my error page is returning a 404 status which is correct (if the original URL were still in the browser address bar

The original URL does stay in the browser bar on my setup.

Let me remote in and see what url path I have been sometime since I set it up.

so in the IIS HTTP header tag 404 is show the url /404.asp

You said file but you mean page right.