Redirects and rewrites
What you need to know
A redirect returns an HTTP navigation instruction; a rewrite serves a destination while preserving the original visible URL. Use redirects for retired addresses and rewrites for intentional aliases.
By the end, you can: compare visible URL behavior; predict destination matching.
Configure a retired URL and an alias
import type { NextConfig } from 'next';const config: NextConfig = { async redirects() { return [{source:'/old-books',destination:'/catalog',permanent:true}]; }, async rewrites() { return [{source:'/shelf',destination:'/catalog'}]; }};export default config;Expected behavior: Direct /old-books should return 308 with a catalog Location; /shelf should serve the catalog without a redirect, assuming no conflicting file route.
How it works
In next.config, async redirects returns rules with source, destination and permanent. Next.js uses 307 for temporary and 308 for permanent redirects, preserving the method. These are HTTP request rules; Pages Router client navigation has documented caveats, so verify direct and client transitions separately. Rewrites can be an array or grouped into beforeFiles, afterFiles and fallback phases. A plain array is checked after filesystem routes and before dynamic routes. beforeFiles can override an existing filesystem route; afterFiles and fallback serve different matching stages. In the Pages Router, a dynamic route using getStaticPaths with fallback true or blocking prevents fallback rewrites from running for that matching route. Verify this case separately from App Router routes. Start with fixed internal destinations. Named path parameters can be reused in destinations when intended; do not route arbitrary input to an external server. Query behavior can differ depending on which parameters are consumed by the destination. A rewrite is not authorization, and it may create duplicate public URLs if used as a canonicalization strategy.
Compare the visible and resolved paths
Request /old-books -> 308 -> /catalog -> pageRequest /shelf -> 200 catalog body; visible /shelfRequest /catalog -> 200 catalog bodyExpected behavior: The status and address-bar behavior distinguish the rules. The 200 assumes an existing successful destination.
Common mistake
Do not use a permanent redirect during an uncertain rollout without considering client caching. Do not define a rewrite that shadows a working route accidentally or forwards untrusted destinations.
Practice and verification
Use the route fixture and record status, Location, visible URL and destination body for each rule. Disable automatic following on the first HTTP check. Recheck client navigation separately.
Scope: Proposed Next.js 16.x, React 19, Node runtime. Root-mounted Pages and mixed-router fixtures with Cache Components disabled; the basePath example is separate. Framework examples are staged, not executed. Exact patched dependencies and platform contracts pending.