question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

middleware rewrite to a SSR page ignored

See original GitHub issue

What 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:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

10reactions
kevinmeyvaertcommented, Dec 2, 2021

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.

2reactions
leerobcommented, Nov 2, 2021

Wrong button 😄

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found