4

..I have a Next.js application with multi-language support (English as the default language and German as the secondary one - English is on https://mywebsite.com and German on https://mywebsite.com/de).

I'm using next-sitemap to generate a sitemap for the page using alternate refs to link the English and German versions of the pages. The following is my next-sitemap config:

/** @type {import('next-sitemap').IConfig} */
module.exports = {
  siteUrl: `https://mywebsite.com`,
  generateRobotsTxt: true,
  exclude: ['/app/*', '/social-redirect'],
  robotsTxtOptions: {
    policies: [
      {
        userAgent: '*',
        [process.env.VERCEL_ENV !== 'preview' && process.env.VERCEL_ENV !== 'development'
          ? 'allow'
          : 'disallow']: '/',
      },
    ],
  },
  alternateRefs: [
    {
      href: 'https://mywebsite.com',
      hreflang: 'en',
    },
    {
      href: 'https://mywebsite.com/de',
      hreflang: 'de',
    },
  ],
};

In the generated sitemap the English entries of the sitemap look good. They have the correct alternate refs. But in the German entries of the sitemap, the alternate refs have the language in the path twice, so for example: https://mywebsite.com/de/de/blog. Is this an issue of next-sitemap or am I doing something wrong? I would be glad if someone could help me with that!

Lukas Bals
  • 79
  • 5
  • Try removing the `/de` from the alternate ref's `href`. – juliomalves Oct 19 '22 at 22:53
  • Hi @juliomalves, thanks for your comment - I tried that already. The result is that in the English entries of the sitemap the alternate refs to German are not correct - they just also point to the English version. – Lukas Bals Oct 21 '22 at 08:32

1 Answers1

0

This is also happening to me. I think it is an issue of next-sitemap

In my case I have languages en and en-gb The urls generated are:

  • <xhtml:link rel="alternate" hreflang="en" href="http://localhost:3000/en/en-gb/blog/"/>
  • <xhtml:link rel="alternate" hreflang="en-gb" href="http://localhost:3000/en-gb/en-gb/blog/"/>

You can use transform prop of next-sitemap.config.js to configure a replacement

`transform: async (config, path) => {
         return { ...config,
                 loc: path.replace('/en-gb/en-gb', '/en-gb')
                } 
}
Jose Maeso
  • 21
  • 3