Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

339
Vistas
How to remove locale string from sitemap for default language in Next.js?

I display my website in two languages: French and English. I built my sitemap and I realised instead of having in my sitemap.xml this:

/blog
/en-US/blog

I have :

/fr-FR/blog
/en-US/blog

I would like to remove the fr-FR string from my sitemaps because it causes a duplication of page which is bad for SEO. How can I do that? Also how to indicate canonical pages on an XML ?

Here is my i18n config:

i18n: {
    locales: ["fr-FR", "en-US"],
    defaultLocale: "fr-FR"
 }

And my getStaticPaths look like this:

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 use 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`
        ]
    }  
}

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>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use the transform property in next-sitemap.js to remove the default locale from the generated paths.

module.exports = {
    // Other `next-sitemap.js` config here
    transform: async (config, path) => {
        return {
            loc: path.replace('/fr-FR', ''), // Remove `/fr-FR` from paths - could get value from i18n config to make it dynamic
            changefreq: config.changefreq,
            priority: config.priority,
            lastmod: config.autoLastmod ? new Date().toISOString() : undefined,
            alternateRefs: config.alternateRefs ?? []
        }
    }
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda