Redirection url from repeteable pages

Hello,

I would like to know if it's possible to perform a redirection for "nomdusite/:uid" coming from multiple repeatable pages?

For example:

-blog
    -[uid].jsx
-episodes
    -[uid].jsx
-cgv
   -[uid].jsx

Instead of having "nomdusite/blog/:uid", "nomdusite/episodes/:uid", "nomdusite/cgv/:uid", I would like everything to redirect to "nomdusite/:uid". I tried to do it as follows in the next.config, but it only works for the blog:

  async rewrites() {
    const routes = ['blog', 'episodes', 'cgv']
    const rewrites = []

    routes.forEach((route) => {
      rewrites.push({
        destination: `/${route}/:uid`,
        source: '/:uid',
      })
    })

    return rewrites
  },

Thanks !

Hello @ducuingg

Thanks for reaching out to us.

I haven't achieved this before. I am trying to find a solution and will return it to you.

Thanks,
Priyanka

Hey @ducuingg , I think Routing: Dynamic Routes | Next.js is what you are looking for :)

2 Likes