Categories
Main

UPHPU meeting on custom 404 pages

When you try to visit a web page that doesn’t exist, the server usually returns a 404 error message — “Page Not Found”. At the Utah PHP Users group meeting last Thursday, Mac Newbold presented on custom 404 pages. Custom 404 pages can help maintain your website branding, help you fix broken links, and help your users find something useful when they don’t find what they’re looking for.

For example, if you visit a page on Apple.com that doesn’t exist, instead of giving you a generic black & white error message that you might normally get, Apple gives you a “friendly” page with their logo and some links to things you might like.

Custom 404 pages are even more powerful when you combine them with PHP. I certainly didn’t expect the flood of ideas that Mac presented for using custom 404 pages:

  • To use a PHP-based custom 404 page, put this in your .htaccess file:
    ErrorDocument 404 /my_404_handler.php
  • Send yourself an email whenever someone gets a 404 message. This will let you know which page to fix on your site.
  • One local programmer (dataw0lf) set up his custom error page to automatically send an email to the webmaster of any referring site that had broken links to his site.
  • Have your custom error page search your site for something similar to what the user requested and forward the user to that page. Php.net does an excellent job of this. You can type in “php.net/” followed by function name or topic and it will find the documentation for that topic or a close match. This is great for usability.
  • If you switch site structure, keep a table of old URLs and new URLs. If someone requests an old URL, redirect them to the new one. …and without having to bother with mod_rewrite.
  • John Taber suggested you could use custom error pages on an unfinished site. Keep a tally of the unbuilt pages that are clicked the most, then build those first.
  • Use custom 404 pages for “virtual marketing campaigns.” Use URLs like example.com/tv or example.com/radio in your marketing, but then forward the user to the same place without having to build separate pages.
  • Mac uses custom 404 pages to build logos on the fly. He links to a specially formatted URL in his tags and then dynamically creates the logos with GD and ImageMagick.

It was a great presentation by Mac.