It seems bots like Google are having problems requesting the sitemap because they first issue a HEAD request to check for sitemap existence. This HEAD will fail with a 404. I have adjusted the router so it not only catches the GET (default), but also the HEAD as following. This way the HEAD now returns a 200 OK.
(added: ,
'method' => 'GET|HEAD'
--- mind the comma)
'routes' => [
[
'pattern' => 'sitemap.xml',
'action' => function(){
// get function that will be used to generate sitemap::
$mapper = option('kirbyzone.sitemapper.customMap');
// generate sitemap:
$map = $mapper(site());
$hasExtraPages = option('kirbyzone.sitemapper.extraPages');
if(is_callable($hasExtraPages)){
$extra = $hasExtraPages(site());
$map = array_merge($map, $extra);
}
//build the xml document:
$content = snippet('sitemapper/xml', ['map' => $map], true);
// return response with correct header type
return new Kirby\Cms\Response($content, 'application/xml');
},
'method' => 'GET|HEAD'
],
It seems bots like Google are having problems requesting the sitemap because they first issue a HEAD request to check for sitemap existence. This HEAD will fail with a 404. I have adjusted the router so it not only catches the GET (default), but also the HEAD as following. This way the HEAD now returns a 200 OK.
(added: , 'method' => 'GET|HEAD' --- mind the comma)
'routes' => [ [ 'pattern' => 'sitemap.xml', 'action' => function(){ // get function that will be used to generate sitemap:: $mapper = option('kirbyzone.sitemapper.customMap'); // generate sitemap: $map = $mapper(site()); $hasExtraPages = option('kirbyzone.sitemapper.extraPages'); if(is_callable($hasExtraPages)){ $extra = $hasExtraPages(site()); $map = array_merge($map, $extra); } //build the xml document: $content = snippet('sitemapper/xml', ['map' => $map], true); // return response with correct header type return new Kirby\Cms\Response($content, 'application/xml'); }, 'method' => 'GET|HEAD' ],