Skip to content
Geecon Global
Book a consultation (opens in a new tab)
Menu

Planning a migration to Contentful

Amol Agre (opens in a new tab), Technical Lead

Published · Reviewed · 8 min read

Direct answer#

Treat a move to Contentful as a scripted, rehearsed project, not a one-off copy. Inventory everything the current site holds, map it to a new content model, and write migration scripts you can run again and again. Then do at least one full trial run that editors check and sign off. At cutover, freeze content, run the final migration, and put a permanent server-side redirect in place for every indexed URL that changes.

Key takeaways

  • Script everything, so the whole migration can run again from scratch.
  • Rehearse end to end until a run needs no manual fixes. How long it takes sets the content freeze.
  • Redirect every indexed URL that changes, permanently and straight to its final page.

Steps or trade-offs#

The stages below apply to most Contentful migration projects, whatever the source system.

A Contentful migration in four phases
  1. Discover

    Inventory content, assets, locales, integrations and URLs, then map them to the new model. Stages 1 and 2.

  2. Build

    Script the content model and the content import so the whole migration can run again from scratch. Stage 3.

  3. Rehearse

    Run it end to end into a fresh environment, check it, fix the scripts and run it again. Stage 4.

  4. Launch

    Freeze content, run the final migration, switch traffic, redirect old URLs and monitor. Stages 5 to 7.

Build and Rehearse form a loop: repeat them until a run needs no manual fixes.

1. Take an inventory#

You cannot migrate what you have not counted. Before anyone designs a content type, list what exists today and who owns it:

  • Content: every content type or template, with a count of items in each, and which ones are still in use.
  • Assets: images, documents and video, including files linked from body text rather than stored in a media library.
  • Locales: which languages and regions exist, and whether every item is translated or only some.
  • Users and roles: who edits what, who approves, and which permissions they need.
  • Integrations: search, forms, commerce, analytics, DAM or PIM feeds, webhooks, and anything else that reads from or writes to the current system.
  • URLs: every public URL, taken from the sitemap, analytics and server logs. This list drives the redirect work later, so start it now.

The inventory also tells you what not to move. Old campaign pages, duplicates and content nobody has opened in years are cheaper to retire than to migrate.

2. Map old structures to the new content model#

Resist copying the old structure field for field. Most older systems store pages as large blocks of HTML, while Contentful works best with structured content types, fields and references between entries. Design the target model first (see content modelling), then map each old type to it.

A mapping sheet with one row per source field works well: source type and field, target content type and field, any transformation, and who owns the decision. Check it against Contentful's constraints as you go:

  • A content type can have up to 50 fields.
  • Short text fields hold up to 256 characters, so long titles or slugs may need a different field type.
  • Reference fields link to other entries and media fields link to assets. Decide where embedded content becomes separate, reusable entries.
  • With field-level localisation, each localised field holds a value per locale. Decide which fields are localised and which are shared, and whether fallback locales cover gaps in translation.

3. Script the migration and make it repeatable#

Every step should be a script you can run again from scratch.

Fix the script, not the space

Manual fixes in the target space are lost the next time you run. If a rehearsal shows a problem, change the script and run it again.

  • Content model as code. The Contentful CLI runs migration scripts with contentful space migration, against a specific environment. Scripts can create and edit content types and fields, and transform existing entries with transformEntries or split content out into new linked entries with deriveLinkedEntries. Keep the scripts in version control and add new scripts rather than editing old ones.
  • Content. A separate script extracts content from the old system, transforms it to match the mapping sheet and writes it through the Content Management API. Keep a record of which old item became which new entry so that reruns and redirects can use it. The API is rate limited and answers with 429 Too Many Requests when you exceed the limit, so build in throttling and retries.
  • Environments. Run everything in a sandbox environment cloned from master. Changes there do not affect other environments, and Contentful states that sandboxes must not be used for production.
  • Space to space. If you are moving between Contentful spaces, contentful space export and contentful space import move content types, entries, assets, locales, webhooks, roles and editor interfaces. Read the limits first: version history is not migrated, drafts are left out unless you include them, the target must use the same default locale, space memberships are not moved, webhooks arrive without credentials, and apps have to be reinstalled.

What makes a content script safe to rerun is how it names entries. If each new entry's ID comes from the old item's ID, a second run updates the entries the first run created instead of adding duplicates, and the ID is also your old-to-new record. A shortened example using the Content Management API's JavaScript client:

// scripts/import-posts.ts
import contentful from 'contentful-management'
 
const client = contentful.createClient(
  { accessToken: process.env.CONTENTFUL_MANAGEMENT_TOKEN! },
  {
    type: 'plain',
    defaults: {
      spaceId: process.env.CONTENTFUL_SPACE_ID!,
      environmentId: 'migration-rehearsal',
    },
  },
)
 
type SourcePost = { id: number; title: string; slug: string }
 
export async function upsertPost(post: SourcePost) {
  // Same source item, same entry ID, on every run
  const entryId = `post-${post.id}`
  const fields = {
    title: { 'en-GB': post.title },
    slug: { 'en-GB': post.slug },
  }
 
  try {
    const entry = await client.entry.get({ entryId })
    return await client.entry.update({ entryId }, { ...entry, fields })
  } catch (error) {
    if ((error as { name?: string }).name !== 'NotFound') throw error
    return await client.entry.createWithId(
      { entryId, contentTypeId: 'blogPost' },
      { fields },
    )
  }
}

Entry IDs can be up to 64 letters, numbers, dots, hyphens or underscores, so prefix them by source type to keep them unique across types.

4. Rehearse with a full trial migration#

A rehearsal is the whole migration, run end to end into a fresh environment, with the results checked as if it were the real thing. Check it in layers:

CheckWhat to comparePasses when
CountsItems per content type, per locale and per asset, against the inventoryEvery difference has an explanation
Spot checksA random sample, plus the awkward cases you know about: the longest article, the page with the most embedded media, the oldest item, anything with unusual charactersEach one matches the source
References and assetsLinks between entries, images and uploaded filesNo broken links, missing images or failed uploads
Rendered pagesA preview build of the new front end, pointed at the rehearsal environment, against key pages on the live siteKey pages look and read the same
RedirectsThe full URL list, run against the preview buildEach URL reaches the right page
Editors' sign-offEach section, reviewed by the people who own the contentThey confirm in writing that they are happy

Time the run. How long it takes tells you how long the content freeze has to be. Repeat the rehearsal until it runs cleanly without manual fixes.

5. Plan the cutover and content freeze#

Agree a freeze window with editors, long enough for the final run and its checks. During the freeze nobody edits the old system. If a freeze is not possible, plan a second, smaller run that picks up items changed after the main one.

On the day, run the final migration, repeat the counts and spot checks, then switch traffic to the new site. Keep the old system available and read-only for a period, so you can compare and, if needed, roll back.

If the target space already serves a live site, environment aliases help here. The master alias can be switched to point at a different environment, which lets you apply content model changes and roll them back when necessary.

6. Redirect every indexed URL#

Any URL that search engines or other sites know about must keep working. Using the URL inventory and the old-to-new record from your scripts, map each old URL to its new one. A few rows from a typical map:

Old URLNew URLCovered by
/news/launch-day/blog/launch-dayOne pattern rule for the whole section, which only moved
/2019/05/spring-sale/blog/spring-saleThe list the migration script writes, because the date was dropped
/about-us.html/aboutA single one-off rule
/old-campaign/campaignsA rule to the closest relevant page, for content you retired. If nothing fits, let it return 404
  • Use server-side permanent redirects (301 or 308). Google treats them as a signal that the new URL should be the one indexed.
  • Redirect straight to the final page. Avoid chains of several redirects.
  • In Next.js, the redirects option in next.config.js handles this, and permanent: true sends a 308. Path patterns such as /blog/:slug can cover a whole section in one rule.
  • Keep redirects in place for as long as possible. Google suggests at least a year.
  • Update internal links to point directly at new URLs, and submit a sitemap listing the new ones.

In Next.js, one pattern rule covers a section whose URLs only moved, and a list written by the migration script covers URLs that changed shape:

// next.config.ts
import type { NextConfig } from 'next'
// Written by the migration script as it creates each entry, e.g.
// [{ "from": "/2019/05/old-post", "to": "/blog/old-post" }]
import redirectList from './redirects.json'
 
const nextConfig: NextConfig = {
  async redirects() {
    return [
      // A whole section that moved, in one rule
      { source: '/news/:slug', destination: '/blog/:slug', permanent: true },
      // One rule per URL that changed shape
      ...redirectList.map(({ from, to }) => ({
        source: from,
        destination: to,
        permanent: true,
      })),
    ]
  },
}
 
export default nextConfig

7. After launch#

Watch Google Search Console as old URLs drop out of the index and new ones appear. Check server logs for 404s and add redirects for anything you missed. Collect editors' feedback in the first weeks, while small model changes are still cheap. Once the new site is stable, archive a final export of the old system, decommission it, and remove sandbox environments you no longer need.

Examples#

For example, a marketing site with a few hundred pages in a page-based CMS, two languages and a blog. Most pages are stored as one large HTML field. The mapping splits those pages into a page type with references to reusable sections, such as a hero, a feature list and a call-out, while blog posts become their own content type. The old blog URLs include the publication date and the new ones do not, so a single pattern redirect is not enough: the migration script writes an old-to-new URL list as it creates each post, and that list becomes the redirect rules. In rehearsal, counts per locale show that some pages were only ever published in one language, which leads to a decision on fallback locales before cutover rather than after.

Or take a team already on Contentful that is merging two spaces into one. Export and import do most of the work, but the inventory shows the two spaces use different default locales, so one has to be resolved before importing. The team also notes that space memberships and webhook credentials have to be recreated by hand, and that apps need reinstalling, and adds those to the cutover checklist.

Primary sources#

[ Next step ]

Talk to us about your Contentful project

Tell us what you are building, changing or supporting. We’ll use the details to understand your requirements and arrange the next conversation.