The Yellow Llama » Web Design South Africa »

web tips, blogs, funny pics... you'll find it all here

Feel free to grab our RSS feed. You must know, we don't post much, but what we do blog, is either helpful or funny... So its win win! You can explore the categories on the left, or just browse our latest articles below.

How to make a useful & dynamic 404 page

So you’ve marketed an article on your site and you’ve got a few backlinks, but then alas.. something happens that results in you having to change the URL structure of your site. How do you NOT lose that traffic that’ll end up at your 404 page?

For example, I had my site running on a Windows *spit* server and as a result, my WordPress permalinks had to be

/index.php/2005/title

And then I moved back to a LAMP Server and my URL’s changed again. The last thing you want is for a bunch of traffic to be lost because of that, or any other change…

The Solution

I made a dynamic 404.php error page that gives the user plenty of guidance as to what went wrong and what they need to do to get where they wanna be.

Firstly, here’s an example of an incorrect URL that gets lots of traffic
http://www.yellow-llama.com/index.php/2005/seo-your-wordpress-blog/

Using a few PHP tricks, you can magically tell the user what URL he was mostly likely looking for:

Get the URL they were looking for

echo ($_SERVER['REQUEST_URI']);

…will display the URI that they attempted to view, in this case: /index.php/2005/seo-your-wordpress-blog/

What I needed to do then, was to…

Trim the unnecessary extras

/index.php/2005/ is what I need to get rid of, so right at the top of my page, I make a simple PHP declaration.

$text = $_SERVER['REQUEST_URI'];
$newtext = substr($text, 15);

Breaking it down
The first line tells the browser that $text is the requested URI.
The second line says that the new element, $newtext is a new substring made up of $text, but starting from the 15th character.

Thus, the resulting $newtext is /seo-your-wordpress-blog/

Making it all work

So now you want to put it all together in a link so that the user doesn’t have to retype the URL, he just has to click on a link that you provide. The link uses PHP (to get your fresh URL) and is put together as follows:

"http://www.yellow-llama.com".$newtext."

Cool huh?

Other must have’s

  • A search box – let the user search for what he was looking for, if he wants…
  • A link to your sitemap (if you have one)
  • A link to your home page
  • A link to other main areas of your site.

Keep the 404 page simple. If possible, strip other navigation off that page and give the user some basic choices to find what he was looking for and keep him happy.
A List Apart also has a very indepth article on a good 404 page if you wanna get really technical.

When traffic hits the wrong page on your site, dont add to their frustration by having a crappy 404 page without any suggestions/help to find what they were looking for. Keep your users happy. Make their lives simple with a good 404 Error page.

Mr eel

You reccomendations are spot on. A good 404 page can go a long way to helping people get what they want. That said, a 404 page alone isn’t enough if you’re changing the URL structure.

In addition the server should be configured to use the 301 http code for permanent redirect, which would just transparently push the user onto the correct URL without them hitting a 404 page.

It’s not particularly difficult if the site’s previous URLs adhere to some system, i.e. you can determine what the new url should be. It’s trivial with blogs for example.

For any site with a large amount of traffic, this is a much better solution than a 404 alone.

for reference:
http://httpd.apache.org/docs/2.0/mod/mod_alias.html#redirectpermanent

the only tricky part is figuring out the regular expression you need if you’re not familiar with them :)

MarkB

Well put Mr eel. Thanks for your comments.

A 301 redirect would also be a great means of overcoming this type of problem. However when you have a few hundred blog posts, it’d be difficult specify each & every post that would need a redirect.

On another site I developped: http://www.sanbi.ac.za, they had a large number of older pages which moved to ww2.sanbi.ac.za. I used this dynamic method to generate a meta refresh tag with the newly created URL so that the user was automatically sent to the ww2 site.

Many ways to skin a cat :)

sparsh

we need website for adventure acadenmy
in this website more than 25 pages content
we need logo design, domain + hosting ,website design and also maintenance

in this website we need flash banner also..

please provide us flash presentation price, presentance is more than 1 min…

waiting for reasonable quote

Thanks
Sparsh

Cosmin

very useful, thanks mate!

Post a comment on this blog

What The Yellow Llama Does Best

WordPress

We won't beat around the bush: We're damn good with WordPress. We can make it do pretty much anything. Contact us and we'll show you how WordPress can help you manage it.

Can The Yellow Llama Help You?

Whilst design & WordPress development are our forté, there's not much else we can't handle. If you need a completely custom application developed, why not give us a shout. If you can explain it, we can build it.

Buy This Space

Care to place an ad here? Let me know: mark[at]yellow-llama.com