























Redirects are rules that instruct Vercel to send users to a different URL than the one they requested. For example, if you rename a public route in your application, adding a redirect ensures there are no broken links for your users.
With redirects on Vercel, you can define HTTP redirects in your application's configuration, regardless of the framework that you are using. Redirects are processed at the Edge across all regions.
acme.com/home, home.acme.com, or www.acme.com), you can choose a canonical URL and use redirects to guide traffic from the other URLs to the chosen one.We recommend using status code 307 or 308 to avoid the ambiguity of non GET methods, which is necessary when your application needs to redirect a public API.
Review the table below to understand which redirect method best fits your use case:
| Redirect method | Use case | Definition location |
|---|---|---|
| Configuration redirects | Support needed for wildcards, pattern matching, and geolocation-based rules. | Framework config or vercel.json |
| Bulk redirects | For large-scale migrations or maintaining extensive redirect lists. It supports many thousands of simple redirects and is performant at scale. | CSV, JSON, or JSONL files |
| Vercel Functions | For complex custom redirect logic. | Route files (code) |
| Middleware | Dynamic redirects that need to update without redeploying. | Middleware file and Edge Config |
| Domain redirects | Domain-level redirects such as www to apex domain. | Dashboard (Domains section) |
| Firewall redirects | Emergency redirects that must execute before other redirects. | Firewall rules (dashboard) |
Use Vercel Functions to implement any redirect logic you need. This may not be optimal depending on the use case.
Any route can redirect requests like so:
For dynamic, critical redirects that need to run on every request, you can use Middleware and Edge Config.
Redirects can be stored in an Edge Config and instantly read from Middleware. This enables you to update redirect values without having to redeploy your website.
Deploy a template to get started.
You can redirect a www subdomain to an apex domain, or other domain redirects, through the Domains section of the dashboard.
In emergency situations, you can also define redirects using Firewall rules to redirect requests to a new page. Firewall redirects execute before CDN configuration redirects (e.g. vercel.json or next.config.js) are evaluated.
GET.GET.You can observe your redirect performance using Observability. The Edge Requests tab shows request counts and cache status for your redirected routes, helping you understand traffic patterns and validate that redirects are working as expected. You can filter by redirect location to analyze specific redirect paths.
Learn more in the Observability Insights documentation.
You can export redirect data by draining logs from your application. Redirect events appear in your runtime logs, allowing you to analyze redirect patterns, debug redirect chains, and track how users move through your site.
To get started, configure a logs drain.
Vercel's CDN automatically normalizes certain URL patterns and redirects with a 308 status code. These normalizations happen before your redirects, rewrites, or application code runs.
The CDN normalizes URLs containing consecutive slashes (e.g., //) to single slashes and redirects with a 308 status code.
For example:
/blog//post redirects to /blog/post//about redirects to /aboutThe CDN does not normalize URL paths to lowercase. URLs are case-sensitive, and requests are served exactly as specified.
For example, /About and /about are treated as different paths. If no content exists at the requested path with the given case, the CDN returns a 404 response.
There are some best practices to keep in mind when implementing redirects in your application:
destination field to avoid hardcoding your domain name此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。