How to Handle Redirects with an Error Page

How to Handle Redirects with an Error Page=

Credit: Flickr

One of the problems with having a large or old website or a site that has seen a few different versions is dealing with pages that have moved and handling redirects. Generally speaking, most sites handle rewrites via htaccess or iisapi. However, once you start to get a lot of redirects, you can encounter performance issues. What I suggest using is combination redirect and 404 error page.

The first thing you’ll need to do is set up a database table. The table needs two fields: old URL and new URL. Basically, we’ll look at the page requested, see if it matches any of the values in the old URL field, and, if it does, get the URL we want to redirect to.

Once that’s set up, develop a custom 404 error page then code the 404 page to handle the lookups and redirects. This is pseudo code, but any competent programmer should be able to use it to work in PHP, ASP, JSP or whatever other scripting language you use:

## this code should execute before any code is sent to the browser
## Get the URL requested
## check the database to see if new URL exists
## if new url exists then issue a 301 redirect to new URL
## if URL does not exist then issue 404 response code and send error page to the browser

That’s it. There’s not much to it as far as coding goes. The tricky part is making sure you don’t send a 200 or 404 response code to the browser when you are doing the redirect. You also want to make sure you you don’t send a 200 response code when you are sending the 404 page. There are plenty of tools to check the response code you are sending. I like check server header tool from SEOConsultants but that’s up to you.

The code is pretty basic but there is room for improving and expanding it. For example you could track all pages with a 404 and write them to a database. If a certain number of entries occur in a single month, you can have it send you an email alert as a way of keeping ahead of potential unexpected problems. If you are tracking 404’s you’ll want to write a script to clean out entries older than 60 days so the table doesn’t get huge.

Another idea would be to track inbound referrering URL’s. If you see someone is sending a lot of traffic to an old URL, you might want to contact them to ask them to make the change directly. A straight link to the proper page is always better than one you have adjusted after the fact.

If you start using a script like this, be wary of the potential to chain 301 redirects together. You want to avoid a 301 redirect into a 301 redirect. The more redirects you pass through the greater the chance a search engine is going to get it wrong. If you have to move something a second time, go back and change the destination URL in the first redirect as well. It’s just good practice for keeping a well-maintained website.

via flickrcc


Enjoyed this Post?

Recommend it to friends and colleagues!
             

no comments posted.

Leave a Reply

Your email address will not be published. Required fields are marked *