normalizeRewrites
Filters and normalizes rewrite routes from Next.js routing phases into Vercel route format.Signature
Parameters
Object containing rewrite routes from three phases.
Return value
Returns an object with the same structure, but with routes normalized to Vercel format:beforeFiles: Routes withcontinue: trueandoverride: true(nocheckproperty)afterFiles: Routes withcheck: truefallback: Routes withcheck: true
Example
modifyWithRewriteHeaders
Modifies rewrite routes by addingx-nextjs-rewritten-path and x-nextjs-rewritten-query headers. Also handles RSC suffix modifications for App Router.
Signature
Parameters
Array of rewrite routes to modify in place.
Whether these are afterFiles rewrites. When true, adds RSC suffix handling.
Whether to handle segment prefetches for PPR (Partial Prerendering).
Behavior
This function mutates therewrites array by:
- Adding rewrite headers to track the original destination
- For
afterFilesrewrites with App Router: modifiessrcregex to match RSC suffixes - Skips external rewrites (those with
http://orhttps://protocol) - Filters out Next.js internal query params (
nxtP*,nxtI*)
Example
extractRedirects
Extracts redirect routes from routing phases and categorizes them by priority.Signature
Parameters
Routing configuration containing routes from multiple phases.
Return value
Returns an object with two arrays:Redirects with
priority: true flag. These have continue: true added.Standard redirects without priority flag.
Notes
Only processes routes with redirect status codes: 301, 302, 303, 307, 308.extractHeaders
Extracts header routes from routing phases.Signature
Parameters
Routing configuration containing routes from multiple phases.
Return value
Returns an array of header routes. Each route has:src: Source regex patternheaders: Headers to applycontinue: true: Continues to next routeimportant: true: Added if route haspriorityflaghas: Optional conditionsmissing: Optional negative conditions
Notes
- Skips routes that are redirects (have redirect status codes)
- Skips routes that are rewrites (have destination property)
normalizeNextDataRoutes
Creates routes to normalize_next/data URLs for middleware data resolving.
Signature
Parameters
Next.js configuration object.
Current build identifier.
Whether middleware data resolving should be handled. Returns empty array if false.
Whether to add
override: true to routes.Return value
Returns an array of routes that:- Add
x-nextjs-dataheader if missing - Strip
_next/data/{buildId}/prefix from URLs - Normalize
/indexroutes to/
denormalizeNextDataRoutes
Creates routes to convert normalized URLs back to_next/data format for middleware.
Signature
Parameters
Same asnormalizeNextDataRoutes.
Return value
Returns an array of routes that convert URLs back to_next/data format when x-nextjs-data header is present.
extractOnMatchRoutes
Extracts routes for the “hit” handle phase that execute when a match is found.Signature
Parameters
Object containing onMatch routes.
Return value
Returns an array of routes with:src: Source regexdest: Optional destinationheaders: Optional headershas/missing: Optional conditionscontinue: trueimportant: true