Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

337
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!