Adds a Redirects collection to Payload 4 where editors define exact-path or regex redirects to a URL or a document, and provides a findRedirect function that a page route calls to send visitors on. Lookups use database indexes, so cost stays constant as the list grows. It works with MongoDB, Postgres and SQLite and requires Payload 4.0.0-beta.12 or later.
Redirects editors manage in Payload 4, found through database indexes at the same cost for any number of them. Every page move a site reports, from its own hook or through @payloadpack/path, suggests a redirect from its old path, which an editor turns on with a yes.
Installation
npm i @payloadpack/redirects10
Stars
0
Forks
0
Open Issues
1 weeks ago
Last Updated
187
Weekly Downloads
v0.1.2
npm Version
260.6 KB
Unpacked Size
1
Dependencies
10+10 since Oct 18
| Date | Stars |
|---|---|
| Dec 6, 2026 | 10 |
| Dec 5, 2026 | 10 |
| Dec 4, 2026 | 10 |
| Dec 3, 2026 | 10 |
| Dec 2, 2026 | 10 |
| Dec 1, 2026 | 10 |
| Nov 30, 2026 | 10 |
| Nov 29, 2026 | 10 |
| Nov 28, 2026 | 9 |
| Nov 27, 2026 | 9 |
| Nov 26, 2026 | 9 |
| Nov 25, 2026 | 9 |
| Nov 24, 2026 | 9 |
| Nov 23, 2026 | 9 |
| Nov 22, 2026 | 9 |
| Nov 21, 2026 | 9 |
| Nov 20, 2026 | 9 |
| Nov 19, 2026 | 9 |
| Nov 18, 2026 | 10 |
| Nov 17, 2026 | 9 |
| Nov 16, 2026 | 8 |
| Nov 15, 2026 | 8 |
| Nov 14, 2026 | 8 |
| Nov 13, 2026 | 8 |
| Nov 12, 2026 | 6 |
| Nov 11, 2026 | 5 |
| Nov 10, 2026 | 3 |
| Nov 9, 2026 | 3 |
| Nov 8, 2026 | 1 |
| Nov 7, 2026 | 1 |
| Nov 6, 2026 | 1 |
| Nov 5, 2026 | 1 |
| Nov 4, 2026 | 1 |
| Nov 3, 2026 | 1 |
| Nov 2, 2026 | 1 |
| Nov 1, 2026 | 1 |
| Oct 31, 2026 | 1 |
| Oct 30, 2026 | 1 |
| Oct 29, 2026 | 1 |
| Oct 28, 2026 | 1 |
| Oct 27, 2026 | 0 |
| Oct 26, 2026 | 0 |
| Oct 25, 2026 | 0 |
| Oct 24, 2026 | 0 |
| Oct 23, 2026 | 0 |
| Oct 22, 2026 | 0 |
| Oct 21, 2026 | 0 |
| Oct 20, 2026 | 0 |
| Oct 19, 2026 | 0 |
| Oct 18, 2026 | 0 |
Shared by 3 plugins in payloadpack/plugins.
196+196 since Nov 23
| Date | Weekly downloads |
|---|---|
| Dec 6, 2026 | 196 |
| Dec 5, 2026 | 269 |
| Dec 4, 2026 | 581 |
| Dec 3, 2026 | 592 |
| Dec 2, 2026 | 620 |
| Dec 1, 2026 | 978 |
| Nov 30, 2026 | 929 |
| Nov 29, 2026 | 896 |
| Nov 28, 2026 | 821 |
| Nov 27, 2026 | 495 |
| Nov 26, 2026 | 476 |
| Nov 25, 2026 | 431 |
| Nov 24, 2026 | 0 |
| Nov 23, 2026 | 0 |
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1428386015-redirects)<a href="https://payloaddirectory.dev/plugins/1428386015-redirects"><img src="https://payloaddirectory.dev/badge/1428386015-redirects.svg" alt="Payload Directory"></a>README
Redirects your editors manage in Payload 4.
Found through database indexes, so a lookup costs the same at 1,000 redirects as at 100,000.
Documentation · Changelog · Contributing
Payload's own @payloadcms/plugin-redirects only stores the list of redirects. On its own it sends no visitor anywhere: your site needs code that finds the redirect and sends the visitor on. Payload's example website, its Website Template, ships that code, so it's Payload's side below.
Finding one redirect, median (p95), with each database on the same machine as the app, so neither side waits on a network. The example website's lookup reads every redirect, and a list this long is too big for Next.js's data cache, so every lookup reads all of them from the database. Next.js still caches each rendered page, so the lookup runs whenever a page or post renders, pages that exist included: at build, on a path's first visit, each time Next.js renders it again, such as after any redirect is saved, and on every request in draft mode.
| Finding one redirect among 100,000 | @payloadpack/redirects | Payload's example website | Times faster | Example website, list cached |
|---|---|---|---|---|
| MongoDB | 0.19 ms (0.3 ms) | 1.3 s (1.4 s) | 6,400× | 33.1 ms (34 ms) |
| Postgres | 0.36 ms (0.43 ms) | 1.3 s (1.3 s) | 3,400× | 32.4 ms (33.2 ms) |
| SQLite | 0.2 ms (0.26 ms) | 1.5 s (1.6 s) | 7,200× | 32.7 ms (34.2 ms) |
With a custom cache handler, which Next.js doesn't hold to 2 MB, the example website's lookup parses the cached list instead and costs at least the last column. At 1,000 redirects, where Next.js's data cache holds the list, it makes no database query: close to ours on the same machine, and faster than ours once the database is a round trip away. With the database elsewhere, ours and the uncached read each wait at least one round trip more, and the uncached read pulls the whole list across it. The plugin indexes from, so a lookup you write yourself can find a redirect in one query where from matches exactly as stored, without regexes, and with a query string only in the order and case it was stored.
| @payloadpack/redirects | Payload's plugin with Payload's example website | |
|---|---|---|
| Sends visitors to their redirect | ✅ The lookup is built in. Your page route calls findRedirect and sends the visitor on, about ten lines. | ❌ Not on its own: the plugin only stores the list. Your site needs code that finds the redirect and sends the visitor. Payload's example website ships about 90 lines of it, in four files. |
Ignores capital letters/About-Us finds the redirect from /about-us | ✅ Any spelling finds it. | ❌ Only the exact spelling. |
Redirects from URLs at any depth/blog/2019/05/opening-hours | ✅ Any URL your site gets, up to 32 levels deep. | ❌ Only /slug and /posts/slug. No route looks up a redirect for a deeper URL. |
Redirects a whole section and keeps the rest of the URL/blog/(.*) → /news/$1 | ✅ One regex redirect. Its groups fill into the new URL as $1 to $9. | ❌ No regexes, and /blog/… is deeper than /slug, so editors can't redirect it. |
Tells old URLs apart by what follows the ?/news.aspx?id=123 and ?id=124 to different pages | ✅ Yes, with the query-string proxy, and with the parameters in any order and case. | ❌ No. Both go wherever /news.aspx goes. |
Keeps campaign tags on the way?utm_source=newsletter | ✅ Kept on the new URL, with the query-string proxy. | ❌ Dropped. |
| Suggests a redirect when a page moves | ✅ Your site reports the move, and an editor turns the suggestion on with one click. | ❌ Nothing. Someone has to notice the old URL and add a redirect by hand. |
Redirects to pages at any depth/about/team/people | ✅ Any page's path, nested or not, in every collection you list, and it follows the page when it moves. | ❌ A picked page goes to /slug and a post to /posts/slug. Any other path must be typed as a URL, which doesn't follow the page when it moves. |
| Permanent or temporary, as editors pick | ✅ Visitors get what the editor picked: permanent (308) or temporary (307). | ❌ The plugin can store one of five status codes editors pick. Payload's example website doesn't turn it on and always sends temporary. |
| Turns a redirect off without deleting it | ✅ Set it to Off. | ❌ Delete it. |
| Catches mistakes when you save a mailto: link to redirect from | ✅ Cleans each one and refuses what can't work. | ❌ Only checks that the fields are filled in and no old URL is used twice. |
Speed shows 1,000 and 10,000 redirects, the exact code each side runs, and how to run the benchmark yourself from this repository.
@payloadpack/path to create one suggestion per moved branch, which an editor answers right on the moved page/news.aspx?id=123 in any order and case, without comparing tracking parameters such as utm_source, which every destination keepsbun add @payloadpack/redirects
Add redirectsPlugin to payload.config.ts with the collections a redirect can send visitors to, buildDocumentPath, and documentSelect:
import { redirectsPlugin } from '@payloadpack/redirects'
import { buildConfig } from 'payload'
export default buildConfig({
plugins: [
redirectsPlugin({
collections: ['pages'],
buildDocumentPath: ({ document }) => `/${document.slug}`,
documentSelect: { slug: true }
})
]
})
With @payloadpack/path, return the path it stores: buildDocumentPath: ({ document }) => document.path with documentSelect: { path: true }.
Look up a redirect in your page route when no document holds the path:
import { findRedirect } from '@payloadpack/redirects'
const { foundRedirect } = await findRedirect({ path: '/old-page', payload })
// { destination: '/new-page', matchedQueryString: false, permanent: true, to: { type: 'document' } } or null
permanent is true for 308 and false for 307. Pass hasDocument to follow chains in one hop, and give visitors read access to published documents in the collections listed in collections.
See the Installation guide, Match query strings in a proxy, and Let redirects win over pages.
To suggest a redirect when a page moves, call suggestRedirects with each document's old and new path. This example covers a collection without drafts:
import type { CollectionAfterChangeHook, CollectionConfig } from 'payload'
import { suggestRedirects } from '@payloadpack/redirects'
// Your site's own way of building a page's path.
const buildPath = (page: { slug: string }) => `/${page.slug}`
const suggestRedirectOnMove: CollectionAfterChangeHook = async ({ doc, operation, previousDoc, req }) => {
if (operation !== 'update') return doc
await suggestRedirects({
changedPaths: [{ collection: 'pages', id: doc.id, from: buildPath(previousDoc), to: buildPath(doc) }],
payload: req.payload,
req
})
return doc
}
export const Pages: CollectionConfig = {
slug: 'pages',
hooks: { afterChange: [suggestRedirectOnMove] },
fields: [{ name: 'slug', type: 'text', required: true }]
}
With @payloadpack/path, pass onPathsChanged: suggestRedirects or call await suggestRedirects(args) inside your existing onPathsChanged. See Suggest redirects on a move.
| Option | Purpose | Default |
|---|---|---|
collections | Collections a redirect can send visitors to a document of | Required |
buildDocumentPath | Builds the path of a document a redirect sends visitors to from the document | Required |
documentSelect | Fields buildDocumentPath reads, so a lookup reads only those | Whole document |
trackingParameters | Extra query string parameters no redirect compares, beside utm_source and the other defaults | Built-in defaults |
winOverDocuments | Lets redirects win over a page at their path: selected redirects ('perRedirect') or every redirect that is On ('always') | Omitted (page wins) |
overrides | Function that takes the Redirects collection and returns it changed | None |
See Configuration, findRedirect, and Refusals and errors.
Without a proxy, your page route asks for a redirect only when no page holds the path, so normal page views pay nothing. With the query-string proxy, this is what it adds to each page view at 100,000 redirects, median (p95). See Speed for how it is measured and how to run it yourself.
| Without a query string | With one, database on the same machine | With one, database 5 ms away | |
|---|---|---|---|
| MongoDB | 0.06 ms (0.09 ms) | 0.62 ms (0.86 ms) | 5.81 ms (6.25 ms) |
| Postgres | 0.08 ms (0.13 ms) | 0.55 ms (0.77 ms) | 5.78 ms (6.02 ms) |
| SQLite | 0.08 ms (0.1 ms) | 0.34 ms (0.53 ms) | Same machine only |
With winOverDocuments, the proxy checks every page view instead and adds:
| Database on the same machine | Database 5 ms away | |
|---|---|---|
| MongoDB | 0.47 ms (0.81 ms) | 5.77 ms (6.25 ms) |
| Postgres | 0.55 ms (0.76 ms) | 5.88 ms (6.81 ms) |
| SQLite | 0.36 ms (0.59 ms) | Same machine only |
Payload 4.0.0-beta.12 or later, with MongoDB, Postgres, or SQLite. @payloadpack/path 0.3.1 or later, if you use it.
Use it in any project, including client work you charge for and products you sell. What you can't do is offer the plugin, or a copy or fork of it, to others as a competing plugin, paid or free. The terms are the PolyForm Perimeter License 1.0.1.
path
Stored, indexed URL paths for Payload 4 pages and posts built from a parent and a slug
75270/wk10v4
payload slug redirects
Records slug changes in Payload and redirects old URLs to the current slug in Next.js
6471/wk3v3
payload page tree
Folder-based hierarchical URL slugs with a visual page tree in the Payload admin
81536/wk19v3
payload redirect
Automatic and manual 301/302 redirect rules stored in a native Payload collection, with cycle validation
793.4k/wk0v3
paths
Stored, queryable document paths for Payload page trees with publish-time uniqueness and a framework-agnostic resolver
60164/wk16v3
redirects
Manage internal and external redirects from the Payload admin panel
100200.1k/wk46.1kv3 v4