docs(proxy): note that existing middleware can intercept the Next.js rewrites proxy path#17784
Open
molockss wants to merge 5 commits into
Open
docs(proxy): note that existing middleware can intercept the Next.js rewrites proxy path#17784molockss wants to merge 5 commits into
molockss wants to merge 5 commits into
Conversation
…rewrites proxy path
Author
|
@bretthoerner @gesh @pauldambra kindly review :) |
sarahxsanders
approved these changes
Jun 19, 2026
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.
Problem
If you set up the reverse proxy on a Next.js app that already has middleware, the middleware can grab the proxy path before the rewrite runs. I hit this with next-intl but it applies to NextAuth or any custom
middleware.ts/proxy.tstoo.In my case next-intl with
localePrefix: 'always'turnedPOST /ingest/sinto a 307 to/en/ingest/s, which 404s. Same for/ingest/eand/ingest/flags. So no events, feature flags, or recordings made it to PostHog.What made it slow to track down: the static SDK assets at
/ingest/static/*.jshave a file extension, so the default next-intl matcher/((?!api|_next|_vercel|.*\\..*).*)skips them and they load fine. PostHog initializes and looks connected. Only the no-extension endpoints get redirected, and those are the ones that actually carry the data.The fix is one line. Add the proxy path to the matcher's negative lookahead:
Change
The rewrites guide doesn't mention any of this. This adds a warning callout in the Setup step and a bullet under "Rewrites not working" so people don't lose an hour to it.
I found this going through the setup wizard, which follows this page. See PostHog/wizard#62 — this is the docs side of that. (Different repo, so it won't auto-close.)