Move redirects into next.config redirects()

next.config redirects run before rendering and return 308 for permanent rules, so old URLs keep their signals without shipping JavaScript. Move server-side redirect maps into redirects(), mark permanent changes permanent, scope rules with has and missing, and keep temporary campaigns separate. Verify with curl that each old path returns one hop and the expected status.

mediumIn codeimpact effort

Why this matters

Declare permanent redirects as configuration, not client code.

Get the full breakdown

The extended brief explains when this works, when it does not, and the trade-offs. Join the waitlist and it unlocks for every tip when sign-in opens; MCP access is the paid part.

Join the waitlist

Before you start

  • Next.js project with a deployed next.config file
  • A list of old paths and their canonical destinations

How to apply it

  1. Collect the current redirect map

    List every old URL that still receives traffic or links, with its destination, from the CMS, middleware, server config and analytics landing pages.

    Check: The list has one destination per source path and marks which moves are permanent.

  2. Declare rules in next.config

    Add an async redirects() export returning source, destination and permanent for each mapping. Use :path parameters for pattern rules and has or missing for scoped cases.

    Check: next.config contains the redirects export and the build completes without a redirect error.

  3. Remove overlapping handlers

    Delete duplicate rules from middleware or hosting config so one path is handled once. Keep client-side navigation redirects out of the crawler path.

    Check: Only one layer defines each source path in the repository.

  4. Test status and hop count

    After deploy, request each old path with curl -sI and follow the chain. Confirm a single hop to a 200 destination with the expected 308 or 307 status.

    Check: curl -sI your production domain/<old-path> shows one location header and the destination returns 200.

Get the prompt for your agent

A ready-to-paste prompt for your agent that implements this tip and verifies the result in your repo.

Join the waitlist

Source: seo-mcp playbook · curated entry · report an error

Framework notes

nextjs-app

Use `redirects()` in `next.config.*` with `permanent: true` for 308s; keep conditional or cookie-based cases in `middleware.ts`.

nextjs-pages

The same `next.config` export applies to the Pages Router; use `has`/`missing` rules to keep broad patterns from swallowing unrelated paths.

Official references

Let your agent apply this + 161 more tips.

Pre-order — $19