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
A redirects collection with from and to fields. Your front-end can fetch these redirects as needed and inject them into your own router. from is a simple string, while to is a conditional field that allows you to select between related documents or a custom url.
Seed
On boot, a seed script is included to create a user, a home page, and a th following redirects for you to test with:
- From
/redirect-to-externaltohttps://payloadcms.com - From
/redirect-to-internalto/redirected