Skip to content

Migration

WordPress to Next.js without breaking URLs

How to plan a WordPress to Next.js migration around your existing addresses, and the cases where staying on WordPress is the better choice.

A URL is the address of a page. Other websites link to it, customers bookmark it and search engines list it. If a migration changes addresses without forwarding them, those visitors land on an error page.

Careful redirects reduce that risk. They do not remove it: search rankings can move during any migration, even a well-run one. Nobody can honestly promise otherwise.

First, decide whether to migrate

Staying on WordPress is often reasonable. Think twice about moving if:

  • The site does its job, and your team publishes comfortably.
  • You depend on plugins for a shop, memberships, bookings or courses. Each of those must be rebuilt or replaced, which can cost more than the rest of the project.
  • The real problem is thin or outdated content. A new framework will not write it.
  • The site is slow for fixable reasons, such as oversized images, too many plugins or weak hosting. Fix those first and measure again.
  • Nobody will be responsible for the new code. A Next.js site needs updates and a developer who can make them.

A move makes more sense when you need custom features, want closer control over speed and page structure, or already use Next.js elsewhere. There is also a middle route: keep WordPress as the editing screen and use Next.js for the pages visitors see. Editors keep a familiar tool, but you now maintain two systems.

1. List every address

Do not rely on the menu. Collect URLs from several places:

  • The sitemap WordPress or your SEO plugin produces.
  • Analytics: pages that visitors land on.
  • Google Search Console: pages shown in search and pages other sites link to.
  • Server logs, if you can get them.
  • A crawl of the live site.

Include category, tag, author and numbered archive pages, feeds such as /feed/, uploaded files such as PDFs and images, old /?p=123 style addresses, and any redirects already stored in a plugin.

2. Make a URL map

A URL map is a spreadsheet that says what happens to each old address.

Old addressNew addressAction
/services//services/Keep
/2023/05/pricing-update//blog/pricing-update/Permanent redirect
/category/news//blog/Permanent redirect
An expired campaign page with no replacementNoneRemove, and return "not found"

Keep addresses unchanged unless there is a clear reason to change them. When a page must move, send it to the closest equivalent. Sending everything to the home page leaves visitors lost.

3. Match the trailing slash

Many WordPress sites end addresses with a slash, as in /about/. By default, Next.js redirects those to the version without one. To keep the original form, set this in next.config.js:

module.exports = {
  trailingSlash: true,
}

Decide this before writing redirects, so that old addresses reach their destination in one step. See the trailingSlash reference.

4. Write the redirects

Next.js has a redirects setting in the same file:

module.exports = {
  trailingSlash: true,
  async redirects() {
    return [
      {
        source: '/category/news/',
        destination: '/blog/',
        permanent: true,
      },
      {
        source: '/',
        has: [{ type: 'query', key: 'p', value: '123' }],
        destination: '/blog/pricing-update/',
        permanent: true,
      },
    ]
  },
}

Details worth knowing:

  • permanent: true sends status code 308, which tells browsers and search engines the move is permanent. Many people say "301 redirect" for any permanent redirect. If you need the code 301 specifically, use statusCode: 301 in place of permanent.
  • Query strings, the part after ?, are passed through to the destination.
  • Redirects are checked before pages and public files.
  • Hosting platforms may limit how many you can add. The Next.js documentation notes a limit of 1,024 on Vercel and suggests a Proxy-based solution for 1,000 or more. See the redirecting guide.

5. Move more than the text

For every page you keep, carry across the title, meta description, canonical address (the preferred URL for that content), headings, image descriptions, share image and structured data. Next.js can set page metadata from code and generate sitemap.xml and robots.txt.

Then list what plugins did quietly: contact forms, spam filtering, site search, comments, analytics tags, cookie notices and scheduled posts. Decide on a replacement for each, or agree to drop it.

Uploaded files need a plan as well. You can serve them from the same paths using the Next.js public folder, or move them to a media service and redirect the old paths.

6. Test before changing the domain

On a preview copy of the new site, request every old address in your map. Each should either load or redirect once to the intended page. Check that removed pages return "not found". Submit every form.

Also confirm that settings used to hide the preview from search engines will not follow the site into production.

7. Launch and watch

Back up the old site and keep it restorable. After switching, submit the new sitemap, check the important addresses again, and watch for errors, indexing problems and changes in landing page traffic. Add missing redirects as you find them. Check closely in the first days, then at intervals for several weeks.

Our migrations include a URL map, permanent redirects, metadata transfer and 30 days of traffic monitoring. Details are on migration and upgrades.

All articles

Tell us about your website

Thirty minutes, no charge. We will say plainly whether we are the right fit.

We reply within 1 business day. Hours: Monday to Friday, 10:00–18:00 IST, except public holidays in Karnataka.