Guide

How to check for broken links after a WordPress migration

You moved the site to a new host, a new domain or https, and the homepage looks fine. The problems hide deeper: posts that still link to the old address, images from an upload folder that didn't come along, and old URLs that other sites link to. Here's a checklist to find and fix them.

Step 1: reset your permalinks

If every page except the homepage gives a 404 after a move, the rewrite rules weren't carried over. Go to Settings > Permalinks and click Save Changes without changing anything. WordPress rewrites the rules, and on Apache it updates .htaccess if it can write to it. On Nginx, check that the server block still sends requests to index.php.

Step 2: replace the old address in the database

WordPress stores full URLs in post content, so links and images in older posts still point to the old domain or to http. Some of them may keep working through a redirect, but each one is a slower detour and breaks as soon as the old domain lapses.

  • With WP-CLI: run wp search-replace 'http://old-domain.com' 'https://new-domain.com' --dry-run to see how many replacements it would make, then run it again without --dry-run. It handles serialized data in options and widgets correctly.
  • Without command line access: the Better Search Replace plugin does the same from the dashboard, also with a dry run.

Take a database backup first. Don't do a plain find and replace on an SQL export file: it breaks serialized data, and widgets or theme settings can silently reset.

Step 3: redirect the old addresses

Other websites, search engines and old emails still use your old URLs. Point them to the new ones with a permanent 301 redirect:

  • New domain: keep the old domain registered and redirect every path on it to the same path on the new domain, at your host or registrar. Redirecting everything to the new homepage throws away the value of links to specific pages.
  • Changed URL structure (for example from /2024/05/post-name/ to /post-name/): add a pattern redirect in .htaccess, Nginx or a redirect plugin.
  • Pages you renamed or merged: add one redirect per page. See how to fix 404 errors with 301 redirects.

Step 4: check every link and image

Now find what the first three steps missed. A crawler such as Screaming Frog SEO Spider works from your computer. To check from inside WordPress instead, the free Hrefix plugin scans the links and images in your published posts, pages and public custom post types on your own server:

  1. Install Hrefix and go to Tools > Hrefix.
  2. Click Start link checking. Hrefix checks the links in small background batches, so a large site takes a while but stays fast for visitors.
  3. Look at the broken links first: these are dead links and missing images. For a broken link to your own site, Hrefix suggests published pages with a similar address and can create the 301 redirect in one click.
  4. Then switch the status filter to Redirects. Each row shows where the link ends up. After a migration these are usually links to your old domain or to http. Fix them in the database with step 2, or edit them one by one in Hrefix.

Hrefix keeps rechecking afterwards: broken links daily, working links weekly. Anything that breaks in the weeks after the move shows up on its own.

Step 5: tell Google

  • Add the new domain as a property in Google Search Console and submit its sitemap.
  • If you changed domain, use Settings > Change of address in the old property.
  • Watch Indexing > Pages for a rise in Not found (404) over the next weeks, and redirect those addresses as they show up.

Quick checklist

  1. Permalinks saved again.
  2. Old domain and http replaced in the database, after a backup and a dry run.
  3. Old URLs redirected path by path with 301s.
  4. All links and images checked, broken ones fixed, redirects cleaned up.
  5. Search Console updated and watched for 404s.

Want this done inside WordPress? Hrefix is a free plugin that finds broken links on your own site, with no account and no cloud service. Hrefix Pro (from €39 per year) adds a 404 monitor, a bulk redirect fixer and a weekly email report.