next-runtime icon indicating copy to clipboard operation
next-runtime copied to clipboard

Transform user rewrites to avoid rewrite stacking

Open ascorbic opened this issue 4 years ago • 1 comments

Currently, Netlify rewrites that point at a Next page fail, because rewrites can't be "stacked". To handle this we should parse user rewrites onPreBuild, find the ones that eventually point at functions, and change them to point at the functions directly, with the full path appended to the function.

e.g. change this:

[[redirects]]
from = "/oldblog/*"
to  = "/newblog/:splat"
status = 200

to this:

[[redirects]]
from = "/oldblog/*"
to  = "/.netlify/functions/___netlify-handler/newblog/:splat"
status = 200

And then in the handler, read the target path and pass it to next/server. This depends on updates to proxy to pass the target URL through to the function in the event.

ascorbic avatar Nov 11 '21 22:11 ascorbic

Probably makes sense to wait for Edge Router https://github.com/netlify/pod-ecosystem-frameworks/issues/62 before tackling this

orinokai avatar Jul 12 '22 09:07 orinokai

Closing this as it works in the v5 runtime.

MarcL avatar Apr 19 '24 11:04 MarcL