Home
Support Forums

Nextjs rewrites on netlify

Site: https://jimmynext--flagship-catalogs.netlify.app/health.html

Migrating from react to nextjs, we need to be able to serve the new page based routes using the react-router method of connecting routes to components.

An example is if I have a route schema like
/:first.html
/:first/:second.html
/blog/:slug
And I point it to a Component, then the specific component will receive the :first and :second as Params. This is great for migrating old sites to react since the :first being dynamic otherwise makes it impossible without a rewrite.

Now in nextjs this is isn’t possible using file based routing. So we use the nextjs config file to do a rewrite which follows a similar pattern. This patterns is also the expressjs pattern.

The project works locally and on vercel deployment just fine. Now when we push it to netlify it doesn’t allow us to break this pattern up. It doesn’t read the nextjs config on ssr (but will do it on client side). And the _redirects file or netlify.toml only lets us use a wildcard match like
/* /:splat
which doesn’t help in serving the other 20 routes that are sitting on the main url e.g /blog/ etc

Is there an undocumented way of performing a similar rewrite as in nextjs or other express based routing schemes?

Hi @mansoor292

Perhaps placeholders is something you could use?

1 Like