This tutorial explains how to set up server-side redirects using Builder's Data model.
Server-side redirects guide visitors from one URL to another before the page loads. Use redirects to phase out old URLs without breaking links or to transition to new naming conventions.
- Redirects run on the server, so the intermediate URL does not display.
- Each redirect maps a source URL to a destination URL and can optionally mark the redirect as permanent with a 301 HTTP status.
- Manage redirects in Builder using a single Data model without code changes until deployment.
- An app in the framework of your choice with the appropriate Builder SDK installed.
- Integrate your app with a Data model. For details, see Integrate with structured Data.
Create a Data Model to define a structured container for your site's URL redirects.
To create a Data model:
- Go to Models.
- Click + Create Model.
- In the Name field, enter
URL Redirects
. - In the Description field, enter
server-side redirects
. - Click Create.
The video below demonstrates creating a new Data model called URL Redirects
:
Add custom fields to the model to store the redirect URLs and other settings for managing redirects in your content entries.
To add custom fields:
- On the Fields tab, click + New Field.
- In the Name field, enter
SourceUrl
and set the Type to Url. - Repeat the process to create
DestinationUrl
with type Url andRedirectToPermanent
with type Boolean. - Click Save.
The video below demonstrates adding custom fields such as SourceUrl, DestinationUrl, and RedirectToPermanent to the Data model.
To create URL Redirects entries:
- Go to Content and click + New Entry.
- Select URL Redirect as the model type.
- In the Name field, enter
/site/intro → /site/get-started
to make the entry easy to identify. - Assign values to each custom field:
SourceUrl
,DestinationUrl
, andRedirectToPermanent
. - Click Save.
The following video demonstrates creating a content entry using the URL Redirects model and setting values for the custom fields.
- Learn how to integrate CMS data into your site.
- Review the concepts behind Data models to structure other dynamic data.
In entry.server.tsx
, import findRedirectByRequestUrl()
and add the redirect logic at the top of the handleRequest()
function.