I have a website using nextjs 10.1
I am using SSG and a catchall strategy, i.e. under /pages, I have
-pages
--[...slug]
---index.tsx
and in my index.tsx I have
export const getStaticProps: GetStaticProps = async (context: any) => {
const { params, locale } = context;
const slug = params.slug;
//multiple slugs can lead to the same page
...
}
export const getStaticPaths: GetStaticPaths = async () => {
...
return {
paths,
// Fallback blocking ensures that pages not listed in getStaticPath will still be rendered with a call to getStaticProps
fallback: 'blocking',
};
}
In my headless cms (primic), slug history is saved (which is quite useful) and then multiple slugs an lead to the same page beacause I also parametered fall As of today, the right canonical tag is rendered for those multiple versions, with a link to the last slug parametered on prismic.
I would prefer a 301.
How can I create a 301 from my getStaticProps or how can I structure my /pages/[catchall] so that I have 301 from old slugs to new ones?
Thanks a lot for the help!