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 -Arun
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:
- If you haven’t modified your
.htaccessfile, then open it and copy paste the following as your first line
ErrorDocument 404 /index.php?error=404
index.phpfrom your template and rename it to
404.phpin the same directory
Remove all sections dealing with posts or comments. Roughly the lines between
< ?php if ( have_posts() )and ``
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”);
You can write pretty much anything in this page. Or you can download my 404 page from here
Check out the results, I’m sure you (and your visitors) would be able appreciate the improvements in the browsing experience.