I have set up my website to be displayed in both French and English languages.
After building my sitemap, I noticed a issue with the URLs listed in my sitemap.xml
. Instead of having:
/blog
/en-US/blog
I found that it displays as:
/fr-FR/blog
/en-US/blog
The presence of the fr-FR
string in my sitemaps is causing duplication of pages, which can negatively impact SEO. How can I remove this string from my sitemaps? Additionally, how do I specify canonical pages in an XML format?
Below is my internationalization configuration:
i18n: {
locales: ["fr-FR", "en-US"],
defaultLocale: "fr-FR"
}
This is what my getStaticPaths
function looks like:
export async function getStaticPaths({ locales }) {
const products = await fetchAPI(`/products`);
const productsData = await products;
const resProductsEn = await fetchAPI(`/products?${enTranslation}`);
const productsDataEn = await resProductsEn;
const paths = []
productsData.map((product) => paths.push(
{ params: { slug : product.slug} }
))
productsDataEn.map((product) => paths.push(
{ params: { slug : product.slug}, locale: 'en-US'}
))
return {
paths,
fallback: true
};
}
I am using next-sitemap to generate my sitemap - next-sitemap.config
:
module.exports = {
siteUrl: process.env.FRONT_END_URL,
generateRobotsTxt: true,
exclude: [
'/test',
'/commande',
'/forgotten-password',
'/reset-password',
'/panier',
'/mon-compte',
'/mon-compte/*',
'/fr-FR',
],
robotsTxtOptions: {
additionalSitemaps: [
`${process.env.FRONT_END_URL}/sitemap.xml`,
`${process.env.FRONT_END_URL}/server-sitemap.xml`,
`${process.env.FRONT_END_URL}/en-server-sitemap.xml`
]
}
}
For a more concrete example:
<url><loc>https://www.website.com/fr-FR/questions-reponses</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-03T18:26:08.673Z</lastmod></url>
<url><loc>https://www.website.com/en-US/questions-reponses</loc><changefreq>daily</changefreq><priority>0.7</priority><lastmod>2021-12-03T18:26:08.673Z</lastmod></url>