Find Broken Links and Create 301 Redirects with Google Analytics

Server headers can be a quick window into the health of your website. If you are running Google Analytics on your website, use the below tutorial to export top landing pages, crawl these pages for HTTP status codes and then create 301 redirects to the best appropriate page.

Export Top Landing Pages from Google Analytics

  • Open Google Analytics and go to Behavior > Content > Top Landing Pages.
  • Save yourself some time and filter out query strings (?).

Export Data from Google Analytics

Google Analytics export 5000 rows
  • Change the number of rows you are viewing to 5000. This is also the max number of rows that you can export.
  • Select export as a spreadsheet.

Trim and Concatenate for the Full URL

  • Delete everything from the spreadsheet except the URL.
  • In the second column create a formula that trims any whitespace from the URL. Also concatenate the full URL of your domain.
    =TRIM(CONCATENATE("http://www.dexone.com",A6))

Get the HTTP Status Codes

  • Download a HTTP Status Checker like Link Sleuth or Screaming Frog
  • Run against the URLs you have downloaded from Google Analytics.
  • Import this data into your spreadsheet.

Sort by HTTP Status Codes

  • Look for status codes that are a 404 error code.
  • Find a new match on your site and create a redirect in your .htaccess file using the format below:

    Redirect 301 /oldpage.html http://www.yourdomain.com/newpage.html
    Redirect 301 /oldpage2.html http://www.yourdomain.com/newpage2.html

Be sure to save a backup copy of your .htaccess file and be sure that you have FTP access to your website before making this change. Need help? Leave your questions in the comments section.

Let us know what you think!