DEV Community

lightdata-tools
lightdata-tools

Posted on

How to test every redirect after a site migration (chains, loops, 301 vs 302)

Disclosure: I build the Redirect Checker actor mentioned near the end. The checklist below works with any tool, including a plain script.

Most traffic loss after a migration comes from a small set of redirect mistakes. Here is what to test, and how to test it at scale.

The six things to check for every old URL

  1. Final status is 200. An old URL that ends in a 404 or 5xx is lost traffic and lost links.
  2. The final URL is the page you intended. A redirect that lands on the home page instead of the matching page is a soft 404 for search engines.
  3. One hop, not a chain. Old to new in one step. Chains (A to B to C) waste crawl budget and slow users. Fix them by pointing A straight to C.
  4. No loops. A to B to A shows up as "too many redirects" and the page is unreachable.
  5. 301 or 308 for permanent moves. A 302, 303 or 307 tells search engines the move is temporary.
  6. Canonical and indexing on the final page. The canonical should point to the final URL itself, and the page should not be noindex.

Build the list first

You need pairs: old URL, expected new URL. Export old URLs from your old sitemap, analytics, or a crawl. Map them in a spreadsheet. If the new site keeps the same paths on a new domain, the expected URL is just the new domain plus the old path.

A minimal script

// check.mjs  (Node 18+)  usage: node check.mjs pairs.csv
import fs from 'node:fs';
const rows = fs.readFileSync(process.argv[2], 'utf8').trim().split('\n').slice(1).map((l) => l.split(','));
for (const [from, to] of rows) {
  let url = from, hops = 0, status;
  while (hops < 10) {
    const r = await fetch(url, { redirect: 'manual' });
    status = r.status;
    if (status >= 300 && status < 400 && r.headers.get('location')) { url = new URL(r.headers.get('location'), url).href; hops++; } else break;
  }
  const ok = url.replace(/\/$/, '') === to.replace(/\/$/, '') && status === 200;
  console.log(ok ? 'PASS' : 'FAIL', hops, status, from, '->', url);
}
Enter fullscreen mode Exit fullscreen mode

This is enough for a few hundred URLs. It does not detect loops, 302 vs 301, canonical tags, or rate limits, and it is sequential.

When the list has thousands of URLs

I made a no-code version as an Apify actor, Redirect Checker for Site Migrations. You paste old-to-new pairs (or give the old sitemap plus the new base URL) and get one row per URL: every hop and status, loops, 301 vs 302, final URL vs expected, canonical, title, H1, noindex, and a PASS / WARN / FAIL result, plus CSV and Markdown reports. It blocks requests to private networks, so it is safe to point at URLs you do not fully trust. Price is $0.30 per 1,000 URLs, and Apify's free monthly credit covers a trial run.

It can run on a schedule, so you can re-check the map weekly for a month after launch, which is when most regressions appear. You can call it from n8n, Make, Zapier or the API.

Whatever tool you use, re-run the check after every deploy that touches routing.

Top comments (0)