A Nearly Perfect 404 Error Page in WordPress

In this seemingly infinite Web
Oh! young browser thou slips
In the middle of a thousand trips
Realising what was just
The apparent reality of pages
Is nothing but a veil of certainity
404 alone is the absolute reality
So a visitor to your website mistypes a URL, what does he see? A nearly blank page with ‘404 error’ emblazoned over it? At least that was my case until I decided to do something about it.

So many great tutorials have been written on creating a 404 Error page. The best in my opinion is at SacramentoWeb. However, the solution the author has proposed leads the user to a search box already filled with a value by second guessing what the user tried to search for. I was looking for a 404 page that already has those results below the search box.

After some research, I finally hacked up some PHP code. The result can be already seen on my site and looks quite impressive. I mean I was quickly addicted to misusing the feature by performing random searches e.g. for hollywood stuff on my site I would try typing !!!

Here is a quick summary of what to do for any template to display these results:

  1. If you haven’t modified your .htaccess file, then open it and copy paste the following as your first line

ErrorDocument 404 /index.php?error=404

  1. Copy index.php from your template and rename it to 404.php in the same directory

  2. Remove all sections dealing with posts or comments. Roughly the lines between < ?php if ( have_posts() ) and ``

  3. Copy the following line to the first line of 404.php. This is to help search engine spiders indicate that this is an error page.

header(“HTTP/1.0 404 Not Found”);

  1. You can write pretty much anything in this page. Or you can download my 404 page from here

  2. Thats it!

Check out the results, I’m sure you (and your visitors) would be able appreciate the improvements in the browsing experience.

Share on: Twitter, Hacker News, Reddit, Facebook, Google+

Posted on: Wed, Mar 1, 2006

Next: ▶  Decaffeination:: A Short Story

Prev: ◀  Forget Sleep: It's Unproductive

Up: ▲  Blog

Hi! Welcome to ArunRocks, an odd collection of writeups on programming, travel, gadgets and practically anything under the sun. This state of affairs could be blamed on the ecelectic interests of your host, Arun Ravindran. He loves programming in several languages especially Python.

Frequent Tags

python (36) django (18) movies (11) productivity (11) tutorial (10) gaming (8) humour (8) creativity (7) featured (7) screencast (7) python3 (6) review (6) programming (5) wordpress (5)

Don't miss any future posts!


comments powered by Disqus