-
Notifications
You must be signed in to change notification settings - Fork 28.9k
Description
Link to the code that reproduces this issue
https://github.com/r34son/middleware-rewrite-repro
To Reproduce
- pnpm dev
- go to http://localhost:3000/unknown - default 404 (not from [locale]/not-found)
- go to http://localhost:3000/en/unknown - default 404 (not from [locale]/not-found)
Current vs. Expected behavior
Current Behavior
When a user visits a non-existent route (e.g., /non-existent-page), the middleware rewrite is not applied, resulting in a standard Next.js 404 page instead of the expected rewritten route.
Example:
User visits: /non-existent-page
Expected: Should be rewritten to /en/non-existent-page and serve content from that path
Actual: Shows Next.js default 404 page without any middleware processing
Expected Behavior
All routes, including non-existent ones (404s), should be processed by the middleware and rewritten according to the configured rules.
Example:
User visits: /non-existent-page
Middleware should: Rewrite to /en/non-existent-page
Result: Either serves content from /en/non-existent-page or shows a custom 404 page from the /en route structure
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:25 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6020
Available memory (MB): 32768
Available CPU cores: 12
Binaries:
Node: 18.20.6
npm: 10.8.2
Yarn: N/A
pnpm: 10.9.0
Relevant Packages:
next: 15.4.2-canary.16 // Latest available version is detected (15.4.2-canary.16).
eslint-config-next: N/A
react: 19.1.0
react-dom: 19.1.0
typescript: 5.8.3
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Middleware
Which stage(s) are affected? (Select all that apply)
next start (local)
Additional context
If you add root not-found page, [locale]/not-found also do not shows on /unknown and /en/unknown