
Template details
Edge Redirects with Upstash
Redirect from a list of redirects both hardcoded and coming from Upstash (Redis), that get evaluated at the edge.
About this template
Edge Redirects with Upstash is a Next.js boilerplate for evaluating URL redirects at the edge, combining hardcoded JSON rules with live redirects stored in Upstash Redis.
What is Edge Redirects with Upstash?
This template is a Next.js example from Vercel that demonstrates how to handle both static and dynamic redirects inside an Edge Middleware function. It accepts a list of redirect rules — 1,000 hardcoded in a JSON file and 9,000 stored in Upstash Redis — and returns the appropriate HTTP redirect response when a request matches. The template runs on the Vercel edge network and is styled with Tailwind CSS.
Key Features
- Hybrid redirect sources — Evaluates a total of 10,000 redirect rules per request: 1,000 from a local JSON file and 9,000 from Upstash Redis.
- Edge middleware execution — Redirect logic runs in the Next.js edge function, so rules are applied in the edge network rather than on an origin server.
- Editable redirects via Upstash — Update the 9,000 Redis-backed redirects at any time through the Upstash REST API or the included population script; no rebuild is needed.
- Build-time JSON redirects — The 1,000 hardcoded rules are faster to evaluate, but changes to them require a new build.
- One-click deploy on Vercel — Clone and deploy with environment variables for UPSTASH_REST_API_DOMAIN and UPSTASH_REST_API_TOKEN, or bootstrap locally with
pnpm create next-app. - Population script —
scripts/upstash.jspopulates Redis with the demo redirects; setPOPULATE_REDISto false to skip this.
Who is it for?
- Edge middleware developers — Use it as a reference for combining static and dynamic data sources inside Next.js middleware.
- Engineering teams — Deploy it to manage a large volume of URL redirects without doubling over origin requests.
- Site reliability engineers — Benchmark the trade-off between fast build-time JSON redirects and the flexibility of Redis-backed redirects.
What can you do with it?
- Marketing teams: maintain up to 9,000 redirects in Upstash Redis for expired landing pages and campaign URLs, applying changes in seconds.
- Product developers: test how many redirect rules can be evaluated at the edge before latency degrades, using the 10,000-rule demo as a baseline.
How does it work?
After cloning and setting the Upstash environment variables, run the script in scripts/upstash.js to populate Redis with the 9,000 redirects. When a request hits the Next.js edge middleware, it first checks the hardcoded JSON redirects; if no match is found, it queries Upstash for a Redis-stored rule and responds with the redirect. The POPULATE_REDIS flag lets you run without the Redis population step.
FAQ
Do I need an Upstash account?
Yes, to populate and read the Redis-backed redirects you need an Upstash account and must set the UPSTASH_REST_API_DOMAIN and UPSTASH_REST_API_TOKEN environment variables.
Can I use the template without Redis?
Yes, set POPULATE_REDIS to false in your environment file. The hardcoded JSON redirects will still work without Upstash.
How many redirects does the demo include?
The demo seeds 10,000 redirects total: 1,000 hardcoded in JSON and 9,000 stored in Upstash Redis.















