Redirects Example for Payload CMS
This example demonstrates how to implement http redirects into Payload CMS using the official Redirects Plugin.
There is a fully working Next.js app tailored specifically for this example which can be found here. Follow the instructions there to get started. If you are setting up redirects for another front-end, please consider contributing to this repo with your own example!
Getting Started
- Clone this repo
cdinto this directory and runyarnornpm installcp .env.example .envto copy the example environment variablesyarn devornpm run devto start the server and seed the databaseopen http://localhost:8000/adminto access the admin panel- Login with email
dev@payloadcms.comand passwordtest
How it works
The Redirects Plugin automatically adds a redirects collection to your config which your front-end can fetch and inject them into its own router. The redirect fields are:
fromThis is a URL string that will be matched against the request path.toThis is a conditional field that allows you to select between related documents or a custom URL.
See the official Redirects Plugin for full details.
Seed
On boot, a seed script is included to create a user, a home page, and a the following redirects for you to test with:
- From
/redirect-to-externaltohttps://payloadcms.com - From
/redirect-to-internalto/redirected