Hello,
Just started playing with v3. Nice work!
I have only run into one problem, probably a problem on my local server configuration but i would like to know how to debug the issue further.
I have followed the guide to create the basic sitemap (https://getkirby.com/docs/cookbook/seo/xmlsitemap ) but whenever i load /sitemap.xml i get a 404 error.
I tracked it down to the route not being recognized. If i change the pattern value to something that is not sitemap.xml
for example sitemapxml
then it works. I imagine there’s gotta be some setting somewhere where my server is actually trying to load a file called sitemap.xml rather than go trough the routing? I thought that .htaccess
took care of this already ( i haven’t changed it from the plainkit-master download).
Im running on localhost on MacOS X.
Any ideas? Thanks.
Are you using the built-in server? As far as I remember it has problems with dots in the route.
Yes i am. I’m running on Mojave 10.14.2
Ok, i’ll check it out again when i upload to my remote.
Thanks
Oddly, I was just having a similar problem, although working on a staging server rather than local, and I was getting a 404 regardless of the dot or not.
Strangely when I moved the sitemap routes into a plugin rather than in config.php they work perfectly.
kevq
September 18, 2023, 8:34am
5
Was a solution ever found for this? I’m seeing the same issue when creating the sitemap from the Cookbook.
texnixe
September 18, 2023, 8:43am
6
Could you please post the contents of your config.php?
Please also indicate your Kirby version and environment!
kevq
September 18, 2023, 8:52am
7
Sure, I’m running Kirby 3.9.6.1 using the local PHP server (version 8.2.10) and I’m running on MacOS Ventura 13.5.2.
Here’s the output of me config file:
<?php
return [
'debug' => true,
'home' => 'blog',
'markdown' => [
'extra' => true
],
'routes' => [
[
'pattern' => '(:any)',
'action' => function($uid) {
$page = page($uid);
if(!$page) $page = page('blog/' . $uid);
if(!$page) $page = site()->errorPage();
return site()->visit($page);
}
],
[
'pattern' => 'blog/(:any)',
'action' => function($uid) {
go($uid);
}
],
[
'pattern' => 'sitemap.xml',
'action' => function() {
$pages = site()->pages()->index();
// fetch the pages to ignore from the config settings,
// if nothing is set, we ignore the error page
$ignore = kirby()->option('sitemap.ignore', ['error']);
$content = snippet('sitemap', compact('pages', 'ignore'), true);
// return response with correct header type
return new Kirby\Cms\Response($content, 'application/xml');
}
],
[
'pattern' => 'sitemap',
'action' => function() {
return go('sitemap.xml', 301);
}
]
],
'sitemap.ignore' => ['error'],
];
And here’s my sitemap snippet:
<?= '<?xml version="1.0" encoding="utf-8"?>'; ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<?php foreach ($pages as $p): ?>
<?php if (in_array($p->uri(), $ignore)) continue ?>
<url>
<loc><?= html($p->url()) ?></loc>
<lastmod><?= $p->modified('c', 'date') ?></lastmod>
<priority><?= ($p->isHomePage()) ? 1 : number_format(0.5 / $p->depth(), 1) ?></priority>
</url>
<?php endforeach ?>
</urlset>
texnixe
September 18, 2023, 9:00am
8
This also catches the sitemap/sitemap.xml
path! You need to either place this at the end or modify the route like this:
[
'pattern' => '(:any)',
'action' => function($uid) {
$page = page($uid);
if(!$page) {
$page = page('blog/' . $uid);
}
if ($page) {
return site()->visit($page);
}
$this->next();
}
],
1 Like