The new Next.js site is ready, the old WordPress one is still live, and someone asks what happens to all the old links. The quick fix is one rule that sends everything to the homepage.
We skip that rule. Google ranks addresses, and a post that ranked for one search would land on a page that answers something else.
A window company from a small Polish town came to us in 2025 asking whether its Google rankings would drop with the new site. We inventoried 96 old addresses and redirected 71 of them. Of those 71, 38 were tags, date archives and author pages the owner didn't know existed.
Where the old addresses hide
Before we write a single rule, we pull four lists:
- the Pages report in Search Console (what Google has indexed)
- the Links report in Search Console (which subpages other sites link to most)
- the WordPress sitemap
- the list from the old redirect plugin, if the site had one
All of it goes into a spreadsheet with three columns: old address, new address, redirect code. Rows with inbound links from directories and partner sites get the most attention.
The 14, with a target for each
| # | Kind | Example | Redirect to |
|---|---|---|---|
| 1 | www and non-www | www.example.com |
pick one, redirect the other |
| 2 | http and https | http://example.com |
https |
| 3 | Trailing slash |
/offer/ and /offer
|
one form for the whole site |
| 4 | Blog posts | /2023/04/replacing-sockets/ |
that post's new address |
| 5 | Static pages |
/about-us/, /contact/
|
the new equivalent page |
| 6 | Categories | /category/tips/ |
a post list or the matching service page |
| 7 | Tags | /tag/solar/ |
the nearest category or post |
| 8 | Author pages | /author/admin/ |
the About page |
| 9 | Date archives | /2023/04/ |
a post list |
| 10 | Pagination |
/page/2/, /category/tips/page/3/
|
the first page of that list |
| 11 | Attachment pages |
/replacing-sockets/photo-1/, ?attachment_id=57
|
the file, or the post it appears in |
| 12 | Media files | /wp-content/uploads/2023/04/photo.jpg |
the file's new address |
| 13 | RSS feeds |
/feed/, /category/tips/feed/
|
the new feed or a post list |
| 14 | Short links |
?p=123, ?page_id=8
|
the new post or page |
Number 11 depends on how old the install is. Since WordPress 6.4, new installations have attachment pages switched off, but a site upgraded from an older version keeps them on. On old sites we usually find more attachment pages than posts.
Media files get a redirect when they pull traffic from Google Images or other sites link to them. The rest we go through with the client one by one.
Short links like ?p=123 are easy to miss in Next.js, because a redirect source matches the path and the post ID sits in the query string. You match it with has, shown in the config further down. Next.js passes the query string along to the destination, so the new post receives ?p=123 too.
Four we leave as 404
/wp-admin/, /wp-login.php, /xmlrpc.php and search results (?s=) get no redirect. The new site has nothing there.
Our logs show that the requests still coming in for those four are mostly bots looking for vulnerabilities. They keep trying /wp-login.php on a site that no longer runs WordPress.
A directory link that took four hops
On the window company's site, an old link from a business directory went from http with www to https, then to non-www, then to a trailing slash, and only then to the new post. Four hops mean four requests to the server on every visit from a phone.
Most chains we find grow out of the first three rows of the table. So every version of an old address gets one redirect, straight to its final target. Google's site move guide says the same: "we advise redirecting to the final destination directly."
308 for gone, 307 for not yet
Our own studio site had a redirect map dated July 2026, with old addresses the new version no longer uses. Those got a permanent 308, the code Next.js sends for permanent: true. An old WordPress server usually answers with 301, and Google's docs list 301 and 308 together as a permanent move.
If the target page doesn't exist yet, we use a temporary 307 (permanent: false). Browsers don't cache it. When the page goes live we switch the rule to permanent, and no browser is holding on to the old one.
The rules sit in the Next.js config and are read top to bottom; the first match wins. Specific rules go first, and below them a broader one catches any other old address in that section and sends it to the section's list. In the config below, one tag has its own rule and every other tag falls through to the post list.
// next.config.js
module.exports = {
// the old WordPress URLs end with a slash; keep that form so they take one hop
trailingSlash: true,
async redirects() {
return [
// an old post goes straight to its new address
{ source: '/2023/04/old-post-slug', destination: '/blog/new-post-slug/', permanent: true },
// ?p=123 sits in the query string, so the rule needs `has`
{ source: '/', has: [{ type: 'query', key: 'p', value: '123' }], destination: '/blog/new-post-slug/', permanent: true },
// one tag with a close match gets its own rule
{ source: '/tag/solar', destination: '/blog/solar-panels/', permanent: true },
// any other tag falls through to the post list
{ source: '/tag/:slug', destination: '/blog/', permanent: true },
// the new page is not live yet, so 307 for now
{ source: '/old-services', destination: '/services/', permanent: false },
]
},
}
We set trailingSlash: true because every WordPress address in the table ends with a slash. By default, Next.js redirects /tag/heat-pumps/ to /tag/heat-pumps before your rule gets a turn, so each old link takes two hops, or three if the destination ends with a slash too.
You can keep the default and handle slashes another way, as long as the check below shows one hop.
A curl loop before anyone touches DNS
On launch day, before the domain is switched, we run curl over the whole spreadsheet, aimed at the new deployment. Save the sheet as tab-separated text, swap the old domain for the deployment's address in both URL columns, and put a - where a row has no target.
# map.tsv: the spreadsheet saved as tab-separated text: old URL, new URL, code.
# Both URLs point at the new deployment. A row with no target has "-" as new URL.
while IFS=$'\t' read -r old new code; do
code=${code%$'\r'} # spreadsheet exports often end lines with \r
first=$(curl -s -o /dev/null -w '%{http_code}' "$old")
read -r last hops end <<< "$(curl -s -o /dev/null -L -w '%{http_code} %{num_redirects} %{url_effective}' "$old")"
if [ "$code" = 301 ] || [ "$code" = 308 ]; then
[ "$first" = "$code" ] && [ "$hops" = 1 ] && [ "$last" = 200 ] && [ "${end%%\?*}" = "$new" ] && continue
else
[ "$first" = "$code" ] && continue
fi
echo "$old: expected $code to $new, got $first, $hops hop(s), ended $last at $end"
done < map.tsv
It stays quiet for rows that behave. A row gets printed when the first answer has a different code than the sheet says, and a permanent redirect also has to reach a working page on the sheet's address in exactly one hop. We fix whatever it prints before the domain moves.
Thirty days of Search Console
The old site keeps working unchanged until the switch, so visitors never see a gap. Then we repoint the domain's DNS and submit the new sitemap in Search Console.
For the next 30 days we check Search Console for 404s and for queries that lost positions. Every address that shows up goes into the redirect map the same day.
On the window company's site that meant four 404s in a month. All four came from links on external business directories.
In the month before the move the site had 410 clicks from Google, and in the third month after it 430. The rankings held, which answered the owner's question from 2025. A move adds no content, so we don't count on it for growth either.
Our redirects sit in the site's code next to the rest of the config, so they last as long as the site does. Google's guide says to keep them "for as long as possible, generally at least 1 year."
The feed we forgot
We tick off number 13 on every move now, since the one time we left it out. We forgot the RSS feeds on a client's site, and for a month the client's news reader showed an error instead of their posts.
That's our 14, plus the four we leave as 404. Which kind of URL did your WordPress site leave behind that isn't on the list? Add it as number 15 in the comments.
Top comments (2)
For number 15 I'd nominate the AMP versions. Sites that ran the AMP plugin for a year or two often have
/post-slug/amp/or?amp=1URLs that Google indexed, and other sites still link to them. Nobody thinks of them as separate pages, so they don't show up in the spreadsheet and quietly 404 after the move. One wildcard rule to the canonical post covers almost all of them.Runner-up:
?replytocom=links from old comment threads. Harmless, but they show up surprisingly often in that 30-day Search Console check."38 of the 71 were tags, date archives and author pages the owner didn't know existed" is the best argument against the redirect-everything-to-home rule I've seen.
Two more that bite us on moves: feed URLs (podcast apps and aggregators keep polling them) and attachment pages for images and PDFs that other sites link to directly. Do you keep the old sitemap around after launch to recheck crawl errors a month later?