पाठ 19 / 25
Redirects and Configuration
Move URLs without breaking links.
next.config redirects
next.config.ts holds project configuration: redirects, rewrites, headers, image settings, experimental flags. Redirects declared there run before rendering; permanent: true sends a 308 (cached by browsers and search engines), false a 307. Use them when renaming routes so old links and search results keep working. Inside components and actions, redirect() from next/navigation redirects programmatically.
A permanent redirect in next.config.ts
This file is from a small demo store I built with Next.js 16.3.8, React 19.3 and TypeScript; next build compiled and type-checked it successfully. Requests for /catalog are permanently redirected to the home page.
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
async redirects() {
return [{ source: "/catalog", destination: "/", permanent: true }];
},
};
export default nextConfig;Following the redirect, run
I built the demo store with next build (Next.js 16.3.8), started it with next start and requested pages with curl; the output is copied from that run, trimmed to the relevant lines. The permanent redirect is answered with status 308.
curl -s -o /dev/null -w "%{http_code} -> %{redirect_url}" http://localhost:3917/catalog
Output:
308 -> http://localhost:3917/
त्वरित जाँच: Which status does a permanent redirect in next.config use?
- 500
- 200
- 404
- 308
Answer
308 — Permanent redirects preserve the method and are cached.