Over the past few weeks we've been discussing how you prevent 404 errors on your website when removing pages from your website. In parts one, two, and three we looked at how you know which pages could create a costly 404 if they were removed from your website.
By the end of part three, we had a clear indication of which pages, if removed, could become costly 404s. Now, we need to remove those pages while at the same time preventing the 404 error from occurring.
The most effective way to prevent 404 errors when removing pages from your website is by adding redirects. Redirects act like a forwarding address from the post office.
To use our example from the previous parts of this post, let's say you were going to remove blue-widget-overview.html. To prevent that URL from becoming a 404 error, you would want to redirect blue-widget-overview.html to another page on your site. That way, when somebody attempts to access blue-widget-overview.html that person is instead redirected to a different page on your website.
The first step in creating a redirect is to determine where you want visitors to go instead of the page you are removing.
In the example, if you are removing the blue-widget-overview.html page, then it might make sense to redirect that URL to red-widget-overview.html. That way, after you remove the blue-widget-overview.html page, visitors who come looking for that page will instead find the red-widget-overview.html page.
While this may not be precisely what they were looking for, it is closer to what they wanted. Because of that, people are less likely to leave your website (like they would if blue-widget-overview.html returned a 404 error).
Once you decide where to redirect the pages you are removing, you can implement the redirect. Two common ways to implement a redirect are via an htaccess file or via a web.config file. get code samples and learn more about those approaches to adding redirects.
Along with adding the redirects to prevent 404 errors when you remove pages, you will want to remove links to the pages you are removing from your website.
Why? This serves two purposes:
To identify all the links to a certain page, you can, of course, search your website's code for each link. We'll leave that to you and your developer(s) to determine how exactly to do that on your site. However, here are a few quick tips on identify the sources leading to those pages:
The final step in preventing the 404 is to monitor your website (with, say, a tool like SpringTrax) to make sure that your redirects are working properly. It is possible that you will forget to add in a redirect for one of the pages you remove, especially if you remove lots of pages at once.
On occasion, we have also seen websites that accidentally remove redirects and, by doing so, cause several visitors to reach 404 errors. We don't want that to happen to you on your site.
Using a tool like SpringTrax to monitor visits to your 404 pages will instantly alert you if that occurs (as well as alerting you to every other 404 your visitors encounter).
We hope this four part series helps you avoid 404 errors when you remove pages from your website. To recap, all the steps, in order, are: