How to migrate from WordPress to Next.js without losing SEO
Published
Moving from WordPress to Next.js can leave you with a faster site and no plugins to maintain, but your rankings do not move on their own. What Google already knows is your URLs, your titles and your internal links; if they change without a plan, traffic drops. This guide walks through the order that keeps that from happening.
Before you start: do you really need to migrate?
WordPress is still a good fit when an editorial team publishes every day and relies on its visual editor. Migrating makes sense when the effort goes elsewhere: security updates for plugins, a slow site that no caching plugin fully fixes, or custom features the theme cannot support.
If the problem is only a heavy theme, replacing it may be enough. If the problem is the platform, read on.
Pick the path: headless WordPress or a full migration
There are two ways to get to Next.js, and the choice changes everything that follows.
- Headless WordPress: WordPress stays as the content manager and Next.js reads posts through the REST API (/wp-json/wp/v2/posts) or the WPGraphQL plugin. The team keeps writing the same way, but you still maintain and update WordPress.
- Full migration: content moves to Markdown or MDX files in the repository, or to another content manager, and WordPress is shut down. WordPress maintenance goes away, but the publishing workflow changes.
Step 1: inventory every URL
Before writing code, list every URL that exists today. Everything else builds on it, and it is the step people skip most.
Keep it in a sheet with three columns: old URL, new URL and decision (keep, redirect or remove). That sheet later becomes your redirects and your test list.
- The WordPress sitemap: /wp-sitemap.xml since version 5.5, or /sitemap_index.xml if you use Yoast SEO.
- The Search Console Performance report, to know which pages bring clicks and cannot break.
- A crawl of the site, to find what the sitemap does not list.
- What usually gets forgotten: categories, tags, author pages, pagination, attachments and the images under /wp-content/uploads/.
Step 2: keep the URLs or redirect each one
The best outcome is URLs that do not change. If they must change, every old URL should permanently redirect to its closest equivalent. Redirecting everything to the homepage is a common mistake: Google may treat those redirects as soft 404s and not pass their signals on.
In Next.js, redirects live in next.config. With permanent: true, Next.js answers 308, which Google treats as permanent just like a 301. Keep them for at least a year, which is what Google recommends for site moves.
Check the trailing slash too: WordPress URLs usually end with one and Next.js does not by default. To keep them exactly as they are, enable trailingSlash: true and avoid an extra redirect on every page.
// next.config.mjs
const nextConfig = {
async redirects() {
return [
// Date-based WordPress permalinks to the new blog route
{ source: '/:year(\\d{4})/:month(\\d{2})/:slug', destination: '/blog/:slug', permanent: true },
// A renamed page, one to one
{ source: '/quienes-somos', destination: '/nosotros', permanent: true },
]
},
}
export default nextConfigStep 3: carry metadata over page by page
The titles and descriptions you wrote in Yoast or Rank Math are part of what ranks. Export them and assign them to each new page; do not regenerate them from the post title.
With the App Router, each route defines its title, description, canonical and Open Graph in generateMetadata. Set metadataBase in the root layout so relative URLs become absolute.
SEO plugins also generated structured data (JSON-LD) behind the scenes: article, breadcrumbs, organization. If you do not recreate it, it is gone.
// app/blog/[slug]/page.tsx
export async function generateMetadata({ params }) {
const { slug } = await params
const post = await getPost(slug)
return {
title: post.seoTitle,
description: post.seoDescription,
alternates: { canonical: `/blog/${post.slug}` },
openGraph: { title: post.seoTitle, images: [post.image] },
}
}Step 4: images, sitemap and robots
Images live under /wp-content/uploads/ and can get their own traffic from Google Images. Copy that folder with the same path or redirect each image, and keep the alt text.
Generate the sitemap and robots.txt from Next.js (app/sitemap.ts and app/robots.ts) so they update with every new page. Before launch, make sure the production robots.txt is not the staging one, which often blocks the whole site.
Step 5: what WordPress did without you noticing
A WordPress site handles several things through plugins that you have to decide on explicitly in Next.js:
- Forms (for example Contact Form 7): move to an API route or a form service.
- The RSS feed at /feed/: rebuild it if someone consumes it, or redirect it.
- Comments, internal search and author or tag pages: decide whether they migrate, redirect or go away.
- /wp-admin and /wp-login.php: they can return 404; they need no redirect.
Step 6: launch and watch Search Console
Before switching DNS, test every URL in your inventory against the new site. Each one should return 200 if it is kept, or a permanent redirect that ends on a 200 page.
After launch, submit the new sitemap in Search Console, inspect the pages that brought the most traffic and review the Page indexing and Performance reports for several weeks. Google notes that fluctuations are normal during a move; what matters is that important pages get indexed again at their new URL.
# old-urls.txt: one old URL per line, taken from the inventory
while read -r url; do
curl -s -o /dev/null -w "%{http_code} %{redirect_url} $url\n" "$url"
done < old-urls.txtChecklist
If you keep only one part, keep this one:
- A complete URL inventory, with a decision for each one.
- One-to-one permanent redirects, never everything to the homepage.
- A trailing slash consistent with the URLs Google already knows.
- Titles, descriptions, canonical and JSON-LD migrated page by page.
- Images from /wp-content/uploads/ at the same path or redirected.
- Production robots.txt checked before launch.
- New sitemap submitted and Search Console monitored for weeks.