Handling Redirects After a Contentful Migration
Contentful is a highly recommended content management system that helps businesses to build, manage and publish digital content. It is user-friendly and provides a wide range of features that can be customized to suit any business requirements. The migration process from another CMS to Contentful can be smooth, but it can also have some challenges. One of these could be handling redirects. In this post, we will discuss the importance of redirects and options for handling them after a Contentful migration.
Importance of Redirects
Redirects are essential to maintain search engine rankings and prevent broken links. When a website changes its domain or URL structure, it is important to redirect the old URLs to the new ones. If redirects are not implemented, search engines will see the old URLs as broken links, and that can effect your website’s ranking. Redirects also improve user experience by ensuring that users are sent to the correct page even if they have an old link.
How to Handle Redirects after a Contentful Migration
There are two main ways to handle redirects after a Contentful Migration. The first is to store redirects in Contentful as content. The second is to setup redirects at the site configuration level. One thing I won’t be covering in this post is how to manage the redirects in code. Because Contentful is a headless CMS, you could have anything from NextJS to C# to Gatsby running your site. Reach out if you need help implementing this on your site.
Redirects at the Configuration Level
Setting up redirects at the configuration level could be a good option. For example, if you are using a CDN like Cloudflare, you can add Page Rules for redirecting incoming requests. These can even include regex & wildcard functionality. So if you are removing a whole part of your site, you can redirect all requests under that path,
/. If you have a site built on NextJS, you can add a collection of redirects to your
next.config.js file. Another benefit is that you aren't filling up your Contentful space with potentially unnecessary content types and entries.
While this approach has the advantage of potentially handling multiple requests at once, the big disadvantage is that this is harder for editors to manage. For adding the example of adding to site configuration, it may require a technical resource to add and deploy any changes.
Using Contentful to manage redirects involves creating a new content type (or modifying existing ones) for redirects. Generally, there are two approaches to setting up Content Types for redirects. First is to have a specific content type dedicated to redirects. The model for this type could look like the following
The advantage of this approach is it is easier to organize and manage redirects when they are their own separate type. The disadvantage is that you need a dedicated content type for the redirect. Also, you need to have an entry for each redirect. The next option resolves both those issues.
The second way of setting up your Content Types to manage redirects is to have them directly on the page. Your model might end up looking something like this
A disadvantage to this approach is that if you want to have multiple redirects to a specific page, you need to make sure that the redirect URL field on the page is able to handle multiple redirect options (via regex), or you allow for adding multiple entries (Short text, list).
Aside from redirects being editable, another advantage to this approach is that redirects can be added via the Content Management API. If you are migrating from one system to another, you and your previous CMS has a way of exporting the existing redirects, you can migrate them into Contentful.
Redirects are an essential part of any website migration, including a Contentful migration. They ensure that search engine rankings are maintained, and users are sent to the correct page. There are two main ways to handle redirects after a Contentful migration: using the Contentful API or a third-party service. Whichever option is chosen, it is essential to ensure that all redirects are in place before the old URLs are removed to prevent any negative impact on website traffic or search engine rankings.
Thanks to #WOCinTech for the hero/meta photo in this post