Move static redirects out of middleware - #1907
Draft
marcleblanc2 wants to merge 1 commit into
Draft
Conversation
Co-authored-by: Amp <amp@ampcode.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a08e2d-682f-75dd-a050-cb9bf8888dac
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
No description provided. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
next.config.jsnow gives 732 static redirects to Next.js. Vercel serves these from its routing layer, so a redirect does not invoke a function./v/...,/@..., and/changelog.rss. An ordinary page view no longer invokes the edge middleware or scans the redirects array.beforeFilesrewrite handles.mdrequests without middleware.Request handling
Next.js checks a request in this order: headers → redirects → middleware →
beforeFilesrewrites → filesystem routes →afterFilesrewrites → dynamic routes → fallback rewrites. Config redirects therefore finish before middleware and are deployed as Vercel routes rather than function code.The matcher decides which requests can invoke middleware. Narrowing it removes one edge invocation from every ordinary page view while retaining code for version-aware and changelog redirects.
Next automatically prefixes redirect sources and relative destinations with
basePath. Production therefore gets/docs; previews do not. The old middleware always added/docs, including on previews.Redirects remain temporary:
permanent: falseproduces 307, matchingNextResponse.redirect. Changing these to permanent 308 redirects is a separate SEO decision.Route budget and filtering
Vercel permits 2,048 routes per deployment. The data module contains 1,324 rules. Configuration keeps the first duplicate source, matching the old
.find, and removes 386 sources containing fragments plus 206 later duplicates. No query-string sources were present. The result is 732 configured redirects (733 in the manifest including Next's built-in base-path redirect).Fragment sources cannot match because browsers do not send URL fragments to servers. No path-to-regexp-invalid source remained after filtering;
next buildaccepted all 732 routes.Preview checks
Replace
$PREVIEW_URLwith the Vercel preview hostname:Expect, respectively: 307 to
/self-hosted/http-https-configuration; 200 HTML with nox-middleware-*headers; 200text/markdown; 307 to the 5.0 site with the redirected path; 307 to the 5.0 site root; and 307 to the technical changelog feed.Task 5c of the Vercel audit tracked in #1905. Note: this PR and the "run checks once" PR both edit
next.config.js; whichever merges second needs a trivial rebase.