CDN via Sitemap: Relative path to sitemap.xml does not work on multilingual sites

Created on 1 December 2020, over 4 years ago
Updated 6 May 2025, 2 months ago

Problem/Motivation

  • The list of sitemaps can be configured at /admin/config/development/warmer/settings
  • The help text suggests that the path to sitemap.xml can be entered as a relative path e.g. /drupal-sitemap.xml
  • This does not work on multilingual sites because SitemapWarmer::parseSitemap() adds the language prefix.

Steps to reproduce

  • Install multilingual site with at least two languages
  • Configure the language negotiation settings so that the language will be determined by the URL path prefix, for example http://www.example.com/en/foo for English content and http://www.example.com/fi/bar for Finnish content.
  • Build the sitemap.xml using Simple sitemap module .
  • Observe that the URL of the sitemap will be http://www.example.com/sitemap.xml (note that there is no language prefix in the URL).
  • Configure the CDN via Sitemap module so that the URL for sitemap is '/sitemap.xml'. The use of relative path is important so that the module settings can be exported and imported between dev, staging and production environments.
  • Try to warm the caches using drush warmer:enqueue sitemap --run-queue
  • Observe that 0 items are queued for cache warming.

Proposed resolution

The bug seems to be in SitemapWarmer.php

  private function parseSitemaps() {
    ...
    $configuration = $this->getConfiguration();

    // $sitemaps will contain the value '/sitemap.xml' as expected.
    $sitemaps = empty($configuration['sitemaps']) ? [] : $configuration['sitemaps'];

    // $sitemap_urls will contain a URL with language prefix which is incorrect.
    $sitemap_urls = array_map([$this, 'resolveUri'], $sitemaps);

It's very late at the moment so I did not have time to check what the resolveUri callback is but that is anyway resulting in incorrect result in the scenario described above.

Remaining tasks

Figure out a less fragile way to resolve he full URIs of the sitemap files.

User interface changes

None.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇫🇮Finland masipila

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024