# Table of Contents - [Redirects](#redirects) --- # Redirects [](https://vercel.com/docs) Search... ⌘ K Feedback Choose a framework to optimize documentation to: * Next.js (/app) * Next.js (/pages) * SvelteKit * Nuxt * Other frameworks Copy page Redirects ========= 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. There are two types of redirects you can use on Vercel: * [Dynamic](https://vercel.com/docs/redirects#dynamic-redirects) : Dynamic redirects are used to redirect users to a different domain. They can be implemented using Vercel Functions, or Middleware. * [Static](https://vercel.com/docs/redirects#static-redirects) : Static redirects are used to redirect users to a different page on the same domain. They can be implemented using the Vercel dashboard or configuration-based redirects. With redirects on Vercel, you can define HTTP redirects in your application's configuration, regardless of the [framework](https://vercel.com/docs/frameworks) that you are using, including both [dynamic](https://vercel.com/docs/redirects#dynamic-redirects) and [static](https://vercel.com/docs/redirects#static-redirects) redirects. Redirects are processed at the Edge across all regions. [Use cases](https://vercel.com/docs/redirects#use-cases) --------------------------------------------------------- * Moving to a new domain: Redirects help maintain a seamless user experience when moving a website to a new domain by ensuring that visitors and search engines are aware of the new location. * Replacing a removed page: If a page has been moved, temporarily or permanently, you can use redirects to send users to a relevant new page, thus avoiding any negative impact on user experience. * Canonicalization of multiple URLs: If your website can be accessed through several URLs (e.g., `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. * Geolocation-based redirects: Redirects can be configured to consider the source country of requests, enabling tailored experiences for users based on their geographic location. [Dynamic redirects](https://vercel.com/docs/redirects#dynamic-redirects) ------------------------------------------------------------------------- We recommend using the framework-native solution for dynamic redirects. ### [Vercel Functions](https://vercel.com/docs/redirects#vercel-functions) app/api/route.ts Next.js (/app) Next.js (/app)Next.js (/pages)SvelteKitNuxtOther frameworks TypeScript TypeScriptJavaScript import { redirect } from 'next/navigation'; export async function GET(request: Request) { redirect('https://nextjs.org/'); } ### [Middleware](https://vercel.com/docs/redirects#middleware) For dynamic, critical redirects that need to run on every request, you can use [Middleware](https://vercel.com/docs/routing-middleware) and [Edge Config](https://vercel.com/docs/storage/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](https://vercel.com/templates/next.js/maintenance-page) to get started. [Static redirects](https://vercel.com/docs/redirects#static-redirects) ----------------------------------------------------------------------- ### [Dashboard redirects](https://vercel.com/docs/redirects#dashboard-redirects) You can redirect a `www` subdomain to an apex domain, or other domain redirects, through the [Domains](https://vercel.com/docs/projects/domains/deploying-and-redirecting#redirecting-domains) section of the dashboard. ### [Configuration redirects](https://vercel.com/docs/redirects#configuration-redirects) You can use configuration-based redirects to generate routing rules during the build process. This includes temporary redirects (`307`), permanent redirects (`308`), and geolocation-based redirects. Configuration-based redirects can be defined in framework-specific config file or in the `vercel.json` file, which is located in the root of your application. The `vercel.json` should contain a `redirects` field, which is an array of redirect rules. For more information on all available properties, see the [project configuration](https://vercel.com/docs/projects/project-configuration#redirects) docs. When using Next.js, you do _not_ need to use `vercel.json`. Instead, use the framework-native `next.config.js` to define configuration-based redirects. next.config.js module.exports = { async redirects() { return [\ {\ source: '/about',\ destination: '/',\ permanent: true,\ },\ {\ source: '/old-blog/:slug',\ destination: '/news/:slug',\ permanent: true,\ },\ {\ source: '/:path((?!uk/).*)',\ has: [\ {\ type: 'header',\ key: 'x-vercel-ip-country',\ value: 'GB',\ },\ ],\ permanent: false,\ destination: '/uk/:path*',\ },\ ]; }, }; Learn more in the [Next.js documentation](https://nextjs.org/docs/app/building-your-application/routing/redirecting) . When deployed, these redirect rules will be deployed to every [region](https://vercel.com/docs/edge-network/regions) in Vercel's Edge Network. ### [Firewall redirects](https://vercel.com/docs/redirects#firewall-redirects) In emergency situations, you can also define redirects using [Firewall rules](https://vercel.com/docs/security/vercel-waf/examples#emergency-redirect) to redirect requests to a new page. Firewall redirects execute before Edge Network configuration redirects (e.g. `vercel.json` or `next.config.js`) are evaluated. [Redirect status codes](https://vercel.com/docs/redirects#redirect-status-codes) --------------------------------------------------------------------------------- Vercel supports both temporary and permanent redirects. * 307 Temporary Redirect: Not cached by client, the method and body never changed. This type of redirect does not affect SEO and search engines will treat them as normal redirects. * 302 Found: Not cached by client, the method may or may not be changed to `GET`. * 308 Permanent Redirect: Cached by client, the method and body never changed. This type of redirect does not affect SEO and search engines will treat them as normal redirects. * 301 Moved Permanently: Cached by client, the method may or may not be changed to `GET`. 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. [Limits](https://vercel.com/docs/redirects#limits) --------------------------------------------------- The /.well-known path is reserved and cannot be redirected or rewritten. Only Enterprise teams can configure custom SSL. [Contact sales](https://vercel.com/contact/sales) to learn more. ### [Configuration](https://vercel.com/docs/redirects#configuration) If you are exceeding the limits below, we recommend using Middleware and Edge Config to [dynamically read redirect values](https://vercel.com/docs/edge-network/redirects#edge-middleware) . | Limit | Maximum | | --- | --- | | Number of redirects in the array | 1,024 | | String length for `source` and `destination` | 4,096 | [Best practices for implementing redirects](https://vercel.com/docs/redirects#best-practices-for-implementing-redirects) ------------------------------------------------------------------------------------------------------------------------- There are some best practices to keep in mind when implementing redirects in your application: 1. Test thoroughly: Test your redirects thoroughly to ensure they work as expected. Use a [preview deployment](https://vercel.com/docs/deployments/environments#preview-environment-pre-production) to test redirects before deploying them to production 2. Use relative paths: Use relative paths in your `destination` field to avoid hardcoding your domain name 3. Use permanent redirects: Use [permanent redirects](https://vercel.com/docs/redirects#adding-redirects) for permanent URL changes and [temporary redirects](https://vercel.com/docs/redirects#adding-redirects) for temporary changes 4. Use wildcards carefully: Wildcards can be powerful but should be used with caution. For example, if you use a wildcard in a source rule that matches any URL path, you could inadvertently redirect all incoming requests to a single destination, effectively breaking your site. 5. Prioritize HTTPS: Use redirects to enforce HTTPS for all requests to your domain * * * [Previous\ \ Incremental Static Regeneration](https://vercel.com/docs/incremental-static-regeneration) [Next\ \ Rewrites](https://vercel.com/docs/rewrites) Was this helpful? supported. Send ---