Update: As I use different settings now, the suggested tests here WILL NOT WORK.
Often people come to your web site with an incorrect URL, perhaps because they misremember something they saw before, or because someone else has accidentally misdirected them. If you have the ability to redirect 404 (page not found) errors to a custom page, you can help them find what they want.
To show that, let's try a deliberate error on my site: Click on this very incorrect link and see what you get:
There are a lot of things wrong with that link:
Now try this one:
That has the same problems as the first and more: I don't have an article called "disks.html" at all.
Yet in both cases, my custom 404 page gives enough information and suggestions that you could probably find what you wanted immediately.
Actually, in the first case "mod_speling" catches the mistype and fixes it.
Try https://aplawrence.com/ unixaRT/MODemS.HTML. The only thing wrong with that is some incorrect case, which we can fix right up and actually put you on the right page (the Apache module "mod_speling" does the same thing ).
This happens first of all because the Apache server is configured to direct these types of errors to a particular place. This is the line in httpd.conf that does that:
ErrorDocument 404 /errordocs/filenotfound.html
See Apache Book Review for more information on configuring Apache servers.
That by itself can be a big improvement over the standard handling of errors. At least you can apologize for the error, and put in a link to to your search engine or a complete site map.
But I've taken it a bit farther. To do this, I used Server Side Includes (SSI). It's the "mime.types" configuration file that controls SSI parsing; here's the relevant line:
text/x-server-parsed-html html shtml
Here's what the actual 404 error page looks like:
<html><head><title> 404-Page not found </title> <!--#include virtual="/cgi-bin/header.pl?/errordocs/filenotfound.html" --> </head> <body bgcolor="#ffffff"> <p><!--#include virtual="/cgi-bin/body.pl" --> <h2>404- Page not Found</h2> <p> <!--#include virtual="/cgi-bin/rloge.pl" --> <p><!--#include virtual="/cgi-bin/404.pl" --> <a href="https://aplawrence.com/search.html"> searching </a> the site might help you find what you are looking for? <font face="verdana,arial" size=2> <form action="/cgi-bin/search2.pl" method=POST> Search for: <input text name=search size=20> <input type=submit value="Perl Search"> </font> <p> </body> </html> </form>
It wouldn't look like that if you used "View Source" from your browser because the SSI's happen before your browser gets the page.
What happens is that the various SSI scripts ( the stuff that looks like <!--#include virtual="/cgi-bin/404.pl" --> ) get replaced with the text that the scripts output.
The important script for this page is the "404.pl" (the rest just control formatting and the site map at the top of the page). Here's what that looks like:
The "trycase" subroutine corrects many incorrect case problems completely transparently.
Your imagination and, of course, your scripting ability are the only limits here. You could even automatically redirect the person if you are sure you know where they want to go, you could correct bad spelling, or you could do a complete site search and display the results. Whatever you do, it's better than just an error.© January 2000 A.P. Lawrence. All rights reserved
Got something to add? Send me email.
More Articles by Tony Lawrence © 2009-11-07 Tony Lawrence