How to Properly Handle Broken Links to Your Website

Nov
5
2009

Your team has spent the last few weeks and possibly months working on the new website and launch day is here.  Just as you're about to hit the launch button a sinking feeling comes over you.  When doing the new design the site was re-arranged and pages were renamed or deleted.  In the furry of finishing the site on time your team forgot about outside links to the old pages. 

What can you do?

There are a few things that can be done to handle broken outside or internal links to pages. 

1 - Don't Change the Page Address

There is a school of thought that says that you shouldn't ever change the URL of a page or at the very least provide a permanent URL to a page.  In some respects this is a good idea.  You generally don't want to willy-nilly change the address of pages just because you want to or you don't like it.  There should be a valid reason for changing the page address.  A few of those are:

  • For SEO reasons. It's common knowledge that search engines put a lot of stock into the words used in the URL.
  • Poor site architecture.  If the pages of the website aren't organized well it can be hard for customers to find what they're looking for.
  • Changing content management systems. Some content management systems have particular ways that they output URLs.  Moving from one CMS to another might require that the page URLs change. Of course, if you're moving to a search engine friendly content management system, this might not be a bad thing.

2 - Create a Meaningful 404 Error Page

If you try to go to a page on a website that doesn't exist you're often shown some sort of message stating that the page doesn't exist.  This is known as a 404 Error Page.  This is a great opportunity to provide a nice, useful message to the visitor about what happened and how they can find what they're looking for.  If your website has search capabilities then having a search form on that page will be useful.

Not all 404 Error Pages are created equal, though.  It's very frustrating to land on a boring, white, nearly blank page that outputs a not-very-helpful message.

Bad 404 Error Page

For one, it would be more helpful to wrap the page in the design of the site so that the customer feels like they at least got the correct website.  Provide some links on the page on getting to the home page of the site or another page that might be related.  It also doesn't hurt to put a little humor into the page.

Good 404 Error Page

3 - Create Redirects to go to the Right Place

Another good way to handle bad links to the site is to redirect the customer to the correct page or to a page that is more helpful. I personally think that this is one of the better options because the customer doesn't need to know that there was a problem.  It's the Poka-yoke technique.

Redirects can be created a few different ways. 

.htaccess Redirects

Use an .htaccess file and either do a simple redirect or use mod_rewrite to do a redirect. I'm not going to go into great detail here but below are a few simple examples.

An example of a simple redirect would be:
Redirect /pics/ http://www.example.com/images/

An example of a mod_rewrite redirect could be:
RewriteRule ^/docs/(.*)\.html /doctors/$1.htm [L,R]

HTML Refresh Meta Tag

Create an HTML file with the "refresh" meta tag in it for each incoming URL.  You'll need to create a HTML page for each URL that you want to match. If you have a lot of redirects to setup, this might be a nightmare.

You would place this meta tag in the <head></head> section of the HTML. An example tag is:
<meta http-equiv="refresh" content="0;url=http://www.mydomain.com/new-url">

The above tag will redirect to http://www.mydomain.com/new-url 0 seconds after the page loads.  I have noticed though that there is a slight delay in the redirect because the page has to be downloaded and processed. This leads to the next option...

PHP (or another language) Redirect

(I'm a PHP developer so I'm going to use PHP as the example here. You can substitute whatever programing language you use.)

This option is very similar to the HTML refresh meta tag option in that you'll need to create a PHP file for each URL that you want to match.  The difference with this option is that the redirect takes place almost instantly so there is no delay like the HTML option. This is because instead of sending an HTML file with the redirect information in it, the server simply returns a HTTP response instructing the browser to go to another page.  Ideally a 301 response code should be used if the page is permanently gone so that search engines will stop trying to index that page. Some example code is:

<?php header('location: http://mydomain/new-url', true, 301); ?>

View the PHP header documentation for more information.

4 - Use a CMS to Create Redirects

If you have a content management system that allows you to create redirects then this would be a great option.  I cannot speak for other CMSs, but since our CMS, Aptuitiv Studio, lets you create redirects through a nice interface there is no reason anyone should not be directed to where they want to go.

Redirects List

Add a New Redirect

One nifty feature is matching a URL based on a pattern. To use a real-world example we recently upgraded the Franklin Community Health Network website to our CMS. They previously had a custom tool to manage physician profiles.  We used our Directory add-on and customized the URL to be as close as possible to what the profile pages use to be.  The only difference between the new URL and the old URL is an "s".

New: fchn.org/md/profile/adler
Old: fchn.org/md/profiles/adler

We needed to match all requests to fchn.org/md/profiles/WHATEVER and redirect to fchn.org/md/profile/WHATEVER.  We accomplished that by doing the following:

In the Incoming URL to Match field we put:
/md/profiles/*

In the URL to Redirect to field we put:
/md/profile/{#1}

The asterix "*" in the coming URL tells the system to match /md/profiles/WHATEVER.  The {#1} in the redirect URL tells the system to take whatever follows "/md/profiles/" in the request URL and append that to "/md/profile/".

Watch a video on how to create redirects.

I welcome your thoughts on how you handle broken links to your or your client's website.

Leave the first comment