Fixed old path maps to one new path
- Use
redirects()in config- Reason
- Central mapping runs before filesystem routes
Configure redirects in next.config.js, choose 307 or 308 correctly, preserve path parameters, and test the deployed route behavior.
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.
Four quick questions, then a straight answer.
From your answers, this is quietly costing you traffic and nobody has the hours to chase it. Scaplet finds every affected page, drafts the fixes and tracks how AI answers mention you.
A data platform shipped 46 fixes without a ticket.
This looks handled. Re-check after a redesign, a migration or a big content push; that is when it breaks.
Your site is small and you have the time. Work through the steps on this page, starting with the pages that get the most traffic.
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.
module.exports = {
async redirects() {
return [{ source: '/docs/old-guide', destination: '/docs/new-guide', permanent: true }]
},
}: in path parameters; the docs warn that omitting it makes the value literal and can create an accidental loop.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.{ source: '/guides/:path*', destination: '/learn/:path*', permanent: true }redirects() in configredirect or permanentRedirectOne 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.
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.
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.
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.
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.
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.
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.
3 questions people ask next, answered from the sources on this page.
No. The Next.js config maps permanent: true to HTTP 308 and false to HTTP 307. Google treats 308 as a permanent redirect signal.
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.
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.
Run the free audit, then approve the fixes. Every change can be undone.