We have a need for the Drupal sitemap to not exist on sitemap.xml, but instead on something like "sitemap_other.xml".

I went to URL Alias and setup an alias for sitemap.xml > sitemap_other.xml. This worked fine; The overview page (admin/config/search/xmlsitemap) respects it and links to the new URL and Drupal serves the XML file when I request it.

However the paginated index is incorrect:


<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <sitemap><loc>https://www.example.com/sitemap.xml?page=1</loc><lastmod>2019-11-22T09:22Z</lastmod></sitemap>
  <sitemap><loc>https://www.example.com/sitemap.xml?page=2</loc><lastmod>2019-11-22T09:22Z</lastmod></sitemap>
</sitemapindex>

Those URLs do not respect the alias.

CommentFileSizeAuthor
#3 3096159-alias-fix.patch527 bytesnicholasthompson

Comments

nicholasThompson created an issue. See original summary.

nicholasthompson’s picture

So I think this is the relevant code (in xmlsitemap.xmlsitemap.inc)...

  public function generateXML() {
    // @codingStandardsIgnoreEnd
    $lastmod_format = variable_get('xmlsitemap_lastmod_format', XMLSITEMAP_LASTMOD_MEDIUM);

    for ($i = 1; $i <= $this->sitemap->chunks; $i++) {
      $element = array(
        'loc' => $this->getSitemapUrl('sitemap.xml', array('query' => array('page' => $i))),
        // @todo Use the actual lastmod value of the chunk file.
        'lastmod' => gmdate($lastmod_format, REQUEST_TIME),
      );
      $this->writeSitemapElement('sitemap', $element);
    }
  }

Then...

  /**
   * Get Sitemap URL.
   */
  public function getSitemapUrl($path, array $options = array()) {
    global $base_url;
    $options += $this->sitemap->uri['options'];
    $options += array(
      'absolute' => TRUE,
      'base_url' => variable_get('xmlsitemap_base_url', $base_url),
      'language' => language_default(),
      'alias' => TRUE,
    );
    if (!empty($options['protocol_relative'])) {
      $options['base_url'] = preg_replace('~^https?:~', '', $options['base_url']);
    }
    return url($path, $options);
  }

Why do we set alias to TRUE?

> 'alias': Defaults to FALSE. Whether the given path is a URL alias already.

It feels like this shouldn't be set?

nicholasthompson’s picture

Status: Active » Needs review
StatusFileSize
new527 bytes

This seems to fix the problem for us.

However I dont know why that was ever set in the first place?