Avoid 404s with redirects
Redirects ensure that people find your content even after its URL is changed. For instance, when you autogenerate SEO-friendly URLs for your articles, these URLs change when you rename the articles.This lesson explores how to approach redirects based on your needs. All the approaches mentioned here let your business users manage the redirects without any developer help.
Internal redirects
Internal redirects are for redirecting your visitors to another place within your app. Typical use cases are renaming an article, moving it to another category, or archiving it in favor of a newer one.- For a flat hierarchy with short URLs, such as
/blog/best-coffee-grinders
, you only need to redirect URL slugs – the last part of the URL path, usually auto-generated from a title-like text element. - For hierarchical URLs, such as
/blog/coffee/preparation/best-coffee-grinders
, you need to redirect URL slugs and the category parts of your URL paths (coffee
andpreparation
). That’s because when you change the placement of an article in the tree, you need to redirect between the categories.
Redirects for short URLs
If only the last part of the URL changes, you can use a custom element that watches for URL slug changes. The great aspect of this approach is that it works autonomously without human intervention. When the URL slug changes, the custom element saves the previous slug value to a slug history list. Your app can use the list to redirect the old URL slugs to the content item’s current URL.Redirects for hierarchical URLs
For redirecting in a more complex URL hierarchy, you need to save the history of the whole URL path. The URL path consists of the categories in the URL and the URL slug itself. The most intuitive way to keep the URL paths history list is to add a text element to your content items and keep the history list there. When the content item’s URL slug or hierarchy placement changes, insert the previous URL path into the text element.External redirects
To redirect your visitors outside your app, set up external redirects. The “outside” may either be still within your domain or under a completely different domain:- Outside, but still within your domain:
mydomain.org/blog/best-coffee-grinders
→mydomain.org/shop/cofee-grinders
- You have multiple web apps running different parts of your web portal, such as blog and shop, for example.
- You want to shorten a URL, for example,
/blog/best-coffee-grinders
→/good-morning
. - You no longer have a content item for an internal redirect because you archived it, for instance.
- Outside your domain:
mydomain.org/blog/best-coffee-grinders
→somewhere.com/help/coffee
- You have multiple domains and need to redirect between them.
- You decide it’s best to redirect visitors to a 3rd-party website instead of serving them your own content.
Dedicated content type for external redirects
For external redirects, you need an approach different from internal redirects because your app doesn’t control the target landing page. To build rules for external redirects, create a dedicated content type called the Redirect rule, for instance. Add two text elements to this content type, one for the source URL and the other for the target URL. Let’s say you need to redirect frommydomain.org/blog/best-coffee-grinders
to somewhere.com/help/coffee
:
- Create a content item of the Redirect rule type.
- Type
mydomain.org/blog/best-coffee-grinders
into the source URL text element. - Type
somewhere.com/help/coffee
into the target URL field.
301 or 302? Permanent vs. temporary redirects
Sign in with your Kontent.ai credentials or sign up for free to unlock the full lesson, track your progress, and access exclusive expert insights and tips!