i18n rel-alternate-hreflang on a website with a base url

commented 3 months ago



Reproduction link


Steps to reproduce

Hello! ๐Ÿ˜ƒ

I'm trying to use the i18n feature to build a multilingual sitemap, and I'm not getting exactly what I would expect. I'm not sure if I'm missing something in the sitemap-module configuration or if it is a bug.

My Nuxt app is hosted on Github Pages and contains a base url /nuxt-wiki (http://brumartins.github.io/nuxt-wiki). The routes in the <loc> tags are correct, but the alternate links are missing the base url.

Here are the steps to generate the sitemap :

$ npm install

# generate static project (for deployment on Github Pages)
# select first command if using Windows, otherwise select the 2nd one
$ npm run generate:gh-pages-win 
$ npm run generate:gh-pages

Open the dist/sitemap.xml file. The sitemap is great, the translated alternate links are taken into account, but the base url is missing for these alternate links.

What is expected ?

I'd expect a sitemap with

    <xhtml:link rel="alternate" hreflang="fr" href="http://brumartins.github.io/nuxt-wiki/fr"/>
    <xhtml:link rel="alternate" hreflang="en" href="http://brumartins.github.io/nuxt-wiki"/>

What is actually happening?

But I get this (nuxt-wiki base url is missing on alternate links)

    <xhtml:link rel="alternate" hreflang="fr" href="http://brumartins.github.io/fr"/>
    <xhtml:link rel="alternate" hreflang="en" href="http://brumartins.github.io/"/>

Additional comments?

Here is the nuxt configuration (link to full file)

const HOSTNAME = process.env.DEPLOY_ENV === 'GH_PAGES' ? 'http://brumartins.github.io' : 'http://localhost:3000';

export default {
  /* ... */
  sitemap: {
    hostname: HOSTNAME,
    gzip: true,
    i18n: 'en'

I tried to add the base url to hostname property in the nuxt.config.js file. The path in the <loc> tag became http://brumartins.github.io/nuxt-wiki/nuxt-wiki/ and nothing changed for the alternate links.

Thank you in advance for your time ๐Ÿ˜Š

Bug Report โ€ข Open
#c103 - Created 3 months ago