Bug 36977: Google does not read sitemaps with the name sitemapNNNN.xml

We have experienced problems with Google indexing: it seems (controlled
in Google search console) that Google does not "like" sitemaps
with a name like sitemapNNNN.xml (does not read them).  Changing the name
to sitemap_NNNN.xml miraculously resolves the issue: individual pieces of
sitemap are read as they are declared in sitemapindex.xml.

Test plan:
==========
1. Have your site configured to work with Google search console
   (cf. https://support.google.com/webmasters/answer/9008080).
2. Generate sitemap with:
   misc/cronjobs/sitemap.pl --dir /var/lib/koha/<instance>/sitemap
   (create the directory if necessary)
3. Check with you browser that the sitemap is generated:
   http://<OPAC-url>/sitemapindex.xml
   Check that the individual pieces are readeable:
   http://<OPAC-url>/sitemap0001.xml
4. Go to the Google seach console > Sitemaps > Add a new sitemap
   Enter sitemapindex.xml
5. Most probably Google won't read your sitemap chunks with the
   warning: "Couldn't fetch".
6. Apply the patch. Repeat p. 2, 3, 4, with the difference of the
   chunk name:
   http://<OPAC-url>/sitemap_0001.xml
7. You should see Google reading your entire sitemap with the info:
   "Success".

Signed-off-by: Michael Skarupianski <michael.skarupianski@gmail.com>
Signed-off-by: Michał Kula <148193449+mkibp@users.noreply.github.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Janusz Kaczmarek 2024-05-28 20:16:09 +00:00 committed by Katrin Fischer
parent f6052fbb7c
commit 36aa5caab6
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
1 changed files with 2 additions and 2 deletions

View File

@ -72,7 +72,7 @@ sub write {
if ( $self->current == $MAX ) {
$self->_writer_end();
$self->count( $self->count + 1 );
my $w = $self->_writer_create( sprintf("sitemap%04d.xml", $self->count) );
my $w = $self->_writer_create( sprintf("sitemap_%04d.xml", $self->count) );
$w->startTag(
'urlset',
'xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9',
@ -110,7 +110,7 @@ sub end {
for my $i ( 1..$self->count ) {
$w->startTag('sitemap');
$w->startTag('loc');
my $name = sprintf("sitemap%04d.xml", $i);
my $name = sprintf("sitemap_%04d.xml", $i);
$w->characters($self->sitemapper->url . "/$name");
$w->endTag();
$w->startTag('lastmod');