middleware rewrite to a SSR page ignored
See original GitHub issueWhat version of Next.js are you using?
12.0.2
What version of Node.js are you using?
14
What browser are you using?
Chrome
What operating system are you using?
macOS
How are you deploying your application?
Vercel
Describe the Bug
Rewrites in middleware only work if the URL is to an SSG page. When the rewritten URL points to an SSR or ISR page, it is ignored and works like NextResponse.next()
. It does not show the content of the rewritten URL.
Am I not supposed to rewrite to an ISR or SSR page?
Expected Behavior
/hello to rewrite to /bye should show the content of /bye while maintaining the requested URL, /hello. However, it does not have an effect if /bye is an SSR or ISR page.
To Reproduce
in _middleware.ts
NextResponse.rewrite('url-to-ssr-or-isr-page')
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:15 (6 by maintainers)
Top Results From Across the Web
Advanced Features: Middleware - Next.js
Middleware allows you to run code before a request is completed, then based on the incoming request, you can modify the response by...
Read more >Next Js: Middleware is ignored for a directory with re-writes
I have a file system like this. Pages secure/ _middleware.ts protectedResource.tsx _app.tsx _document.tsx index.tsx.
Read more >Routing • Docs • SvelteKit
A +page.svelte component defines a page of your app. By default, pages are rendered both on the server (SSR) for the initial request...
Read more >The router Property - Nuxt
The router property. The router property lets you customize Nuxt router. (vue-router ). base. Type: String; Default: '/'. The base URL of the...
Read more >Headless Chrome: an answer to server-side rendering JS sites
The techniques in this article show how to use the Puppeteer APIs to add server-side rendering (SSR) capabilities to an Express web server....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I am currently experiencing the same issue on a project i’m working on. The rewrite happens correctly when running locally on dev server. But no rewrite happens when deployed to Vercel.
Wrong button 😄