Free auditStart free
GuideNext.js · Routing

Next.js redirects

Configure redirects in next.config.js, choose 307 or 308 correctly, preserve path parameters, and test the deployed route behavior.

5 min
read
6
sources
Oct 24, 2026
updated
Scaplet Editorial Team
author
In one line

Use redirects() in next.config.js for a fixed set of path changes that should run before filesystem routes. Set permanent: true for a lasting move (Next.js returns 308) and false for a temporary one (307). For request-dependent decisions, use a route handler or Proxy instead; then test both the HTTP response and client navigation in the router you use.

30-second check

Where does your site stand?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?
Summarize this page withChatGPTClaudePerplexityGoogleAI Mode
01Check it

Use config redirects for known path changes

Put stable path mappings in the redirects function of the root Next.js config file (next.config.js, .mjs or .ts). Next.js evaluates these rules before the filesystem, so a rule can take precedence over a page or a file under public. Return an array of objects with source, destination, and permanent; keep the mapping small enough that a teammate can review each destination.

Next.js maps permanent: true to HTTP 308 and false to HTTP 307. Its docs say 308 tells clients and search engines to cache the redirect forever, while 307 is temporary and not cached. Google treats 301 and 308 as permanent signals and 302, 303, and 307 as temporary signals. Choose based on whether you intend the source URL to be replaced in search, not because one status number looks more SEO-friendly. See Google's redirect guidance and HTTP status code reference.

Permanent path move
module.exports = {
  async redirects() {
    return [{ source: '/docs/old-guide', destination: '/docs/new-guide', permanent: true }]
  },
}
02Checklist

Match dynamic routes safely

Use named path segments when a section moves intact. A catch-all parameter can carry the remainder of a path, and Next.js passes request query values through to the destination. Include the slash before : in path parameters; the docs warn that omitting it makes the value literal and can create an accidental loop.
First2
Use a one-to-one mapping when a page has a clear replacement. A product docs URL should land on its replacement, not the homepage.
Map supported locale paths deliberately. The App Router docs say locale redirects in config are hardcoded paths; use dynamic route segments and Proxy for per-request locale decisions.
Next1
When basePath is configured, Next.js applies it to matching config redirects by default. Set basePath: false only when a route intentionally sits outside that prefix.
Then1
Keep request-dependent logic out of a static mapping. Use a request-time mechanism documented for the router and runtime you deploy.
Move a documentation section
{ source: '/guides/:path*', destination: '/learn/:path*', permanent: true }
03Choose by what the redirect needs to know

Pick the right Next.js layer

Requirement

Fixed old path maps to one new path

Use
redirects() in config
Reason
Central mapping runs before filesystem routes
Requirement

Destination depends on the incoming request

Use
Route Handler or Proxy
Reason
These can make a request-time decision
Requirement

A Server Component must redirect while rendering

Use
redirect or permanentRedirect
Reason
Application code controls the response
Requirement

Serve another route while keeping the original URL

Use
Rewrite
Reason
A redirect changes the browser URL

One router-specific gotcha matters during migrations: Next.js documents that config redirects in the Pages Router do not apply to client-side routing calls such as Link or router.push unless Proxy is present and matches the path. A direct browser request may work while an in-app link follows a different path. Test both entry points before shipping a broad migration.

04Checklist

Scale a large redirect map without slowing every request

Next.js suggests a custom Proxy solution for 1,000 or more redirects. Proxy is the Next.js 16 name for the file convention earlier versions call Middleware. The deployment platform can impose a lower config limit: the current Next.js guide gives Vercel as an example with a 1,024-redirect limit. Check your host before choosing where the mapping lives; this number is not a universal Next.js limit.
  1. 01Keep the redirect data separate from application code if editors or migration owners need to update it without rebuilding the app.
  2. 02Validate map entries before deployment: source paths should be unique, destinations should resolve, and no path should redirect back to itself or create a cycle.
  3. 03Measure request latency and failures on your actual hosting platform. A lookup strategy that is fast locally may behave differently at the edge or when it reads a remote store.

For a large migration map, the Next.js guide shows storing paths and destinations in a JSON file or key-value store and looking up the incoming pathname in Proxy. Avoid reading a large mapping on every request without measuring it. The guide suggests a fast-read data store or a Bloom filter to quickly reject paths that are not in the map before loading full redirect data.

05How it works

Test the deployed behavior

Keep permanent rules long enough for visitors and crawlers to reach the replacement. Google recommends keeping site-move redirects as long as possible, generally at least one year. Before deploying a large mapping, review it for duplicate sources, cycles, and destinations that return another redirect. On Remix, see Remix redirects.

  1. 01

    Check an old URL over HTTP

    Run curl -sS -D - -o /dev/null https://example.com/old-path. Check the returned status and Location header. Repeat with a trailing slash and query string if those variants receive traffic.

  2. 02

    Follow the chain

    Run curl -sS -L -o /dev/null -w '%{http_code} %{url_effective} %{num_redirects}\n' https://example.com/old-path. Confirm the final page is intended and remove intermediate hops by targeting the final URL.

  3. 03

    Check the destination

    Inspect its canonical URL, robots directive, and content. Update internal links and sitemap entries to point straight to the destination. Google also says to make sure the canonical annotations on a moved site use the new URLs.

  4. 04

    Inspect representative URLs

    For a migration, inspect mapped source and destination URLs in Search Console after deployment. Google recommends testing redirects and submitting the new sitemap; temporary ranking movement can happen while URLs are recrawled.

Questions

Asked a lot.

3 questions people ask next, answered from the sources on this page.

01Does `permanent: true` return a 301 in Next.js?

No. The Next.js config maps permanent: true to HTTP 308 and false to HTTP 307. Google treats 308 as a permanent redirect signal.

02Where do I add redirects in Next.js?

For fixed mappings, add a redirects() function (it can be async) to the root Next.js config file, returning objects with source, destination, and permanent. Use a request-time layer when the result depends on the request.

03Why does my redirect work on refresh but not on a Link click?

Next.js says config redirects do not apply to Pages Router client-side routing calls unless Proxy is present and matches the path. Test direct requests and in-app navigation separately.

Sources · 6

Every fact, linked and dated.

Official docs first. The date is when we last opened each page.
  • nextjs.org
  • google.com
  1. 01redirects | Next.jsnextjs.org · checked 2026-10-24
  2. 02Redirecting | Next.jsnextjs.org · checked 2026-10-24
  3. 03rewrites | Next.jsnextjs.org · checked 2026-10-24
  4. 04Proxy | Next.jsnextjs.org · checked 2026-10-24
  5. 05Redirects and Google Search | Google Search Centraldevelopers.google.com · checked 2026-10-24
  6. 06Site Moves and Migrations | Google Search Centraldevelopers.google.com · checked 2026-10-24
Free · 2 minutes

Tools point. Agencies advise. This one ships.

Run the free audit, then approve the fixes. Every change can be undone.

Free, no card60 secondsNobody will call you
  • 46 fixes shipped without a ticket Brightpipe
  • 0→7 ChatGPT citations in six weeks Paylane