How To Fix Broken Links In Bulk

If you run a bigger site it can be time consuming to fix individual 404 errors, especially low priority 404 errors. For high priority 404s, that are visited by lots of people, it is worth taking the time to implement solutions to fix each specific 404. However, when you have lots of low priority 404s that will take lots of time to fix individually, it can be helpful to fix those 404s at once.

Trick #1: Pattern-Based Solutions

A news website had was delivering an ad that led the people who clicked on it to a 404 error. The ad sent people to over 1000 different 404 errors on this news site, each with a different URL.

These 404s were causing a a huge problem for thousands of visitors on the site and because of that, these 404s were costing the news site hundreds of dollars in ad revenue. Clearly, these 404s needed to be fixed. The problem was that implementing over 1000 different redirects to fix these 404s (link) would be a tedious, time-consuming task.

However, the 404 URLs all followed the same pattern. All the URLs included "InfinityIFrame", but with variances in other parts of the URL. All of these thousands of 404 errors needed to be redirected to the same location, so the news website implemented a solution to fix all of these 404s at once.

The following PHP code was placed on the site's 404 error page. It says, if the requested URL (the broken URL) contains InfinityIFrame.html, then redirect the person looking for this page to a different page on the site. As a result, the thousands of visitors who were arriving on a 404 error page, would now arrive on /infinity-landing-page/index.html.

<?php
if (strpos($_SERVER['REQUEST_URI'], 'InfinityIFrame.html') !== false) { // if this url contains InfinityIFrame.html
   header('HTTP/1.1 301 Moved Permanently'); // permanent redirect
   header("Location: /infinity-landing-page/index.html"); // to new landing page for this error
   exit;
}
?>

The /infinity-landing-page/index.html page contained content that the visitors clicking on this ad were looking for. As a result, the news website quit losing visitors and quit losing ad revenue due to these 404s. But, the news website also didn't have to invest several hours in fixing each 404 error individually.

Trick #2: Correct Common Typos

Another common cause of many 404 errors are typos. Often times, common typos can cause you to have lots of low priority 404 errors on your site which are too time consuming to fix individually. Instead, you want to try to fix those common typos at once.

A non-profit site using SpringTrax noticed that several of their 404 pages resulted from people leaving off the final character of the URL. The URL on this site should have "/something.html". However, dozens of visitors each day were arriving at 404s with URLs like "/something.htm". The "l" in the ".html" was missing and causing 404s. These 404s were resulting from social networking sites and blogs, likely because the person who posted the URL copied and pasted the URL incorrectly (leaving off that final l).

To fix all of these 404 errors at once, the non-profit added the following code to their website's 404 error page. This code checks if the broken URL ends in .htm. If so, the code then add an "l" to the end of the URL and sends the user to that URL instead. By doing so, a visitor arriving on a 404 error with the URL of "/something.htm" is redirected to "/something.html".

<?php
if (substr($_SERVER['REQUEST_URI'], -3) == 'htm') { // if this url ends in "htm"
   $redirect_url = $_SERVER['REQUEST_URI'].'l'; // add "l" to end of URL
   header('HTTP/1.1 301 Moved Permanently'); // permanent redirect
   header("Location: $redirect_url"); // redirect
   exit;
}
?>

Trick #3: Detect Common Phrases

A travel agent using SpringTrax noticed that several of her 404 errors resulted from vacation packages that had been removed from her website. Unfortunately, by the time she installed SpringTrax and realized this, her website had been online for over five years. The travel agent's site was plagued with thousands of 404 errors stemming from old vacation packages that had been removed from the site.

While about a hundred vacation package pages were important enough to fix individually, based on visitor patterns to those errors, the remainder were errors that needed to be fixed in bulk. So, after adding in the individual redirects, the travel agent's developers also added in code to redirect any 404 error back to the appropriate tour category page.

For instance, the code snippet below shows that any 404 error that contained "europe-tours" would be redirected back to the main Europe category page.

<?php
if (strpos($_SERVER['REQUEST_URI'], '/europe-tours/') !== false) { // if this url contains /europe-tours/
   $_SESSION['redirect_message'] = 1; // set flag
   header('HTTP/1.1 301 Moved Permanently'); // permanent redirect
   header("Location: /europe.php"); // to europe category page
   exit;
}
?>

You might also notice the "$_SESSION['redirect_message'] = 1;" part of this code. To help visitors understand why they were on the main category page instead of the vacation they wanted, the travel agent wanted to add a message specific for these visitors explaining that they were looking for an old vacation. To do this, the developers added "$_SESSION['redirect_message'] = 1;" into the code, which set a cookie, or flag. On the main category pages, the developers then added code that detected this flag/cookie. For example, here was the code on the Europe page:

<?php
if (isset($_SESSION['redirect_message']) && $_SESSION['redirect_message'] == 1) { // if flag is set
   $_SESSION['redirect_message'] = 0; // clear flag
   echo '<div class="message">We\'re sorry, but the vacation package you requested is no longer available. Please select another vacation to Europe below.</div>'; // show message
}
?>


 

Share This Post


Add Comments

comments powered by Disqus

Are You Ready To Quit Losing Customers?

Sign Up Today To Find & Fix Every 404 Error On Your Website.


Sign Up Today

Starts at $19.99/month. 30 day money back guarantee. Cancel at any time.