Hello there
i am using this reference for my sitemap:
https://getkirby.com/docs/cookbook/xmlsitemap
But my sitemap is not generated as a XML view. Just plain html output.
Are there any known issues?
Thank you
Hello there
i am using this reference for my sitemap:
https://getkirby.com/docs/cookbook/xmlsitemap
But my sitemap is not generated as a XML view. Just plain html output.
Are there any known issues?
Thank you
What do you mean by “just plain HTML output”? I don’t think there is an issue, works in my environment.
That does Not Look Well formated as XML
If I look at your “page source”, it looks very well…, e.g. in Firefox I need this trick to view the real source.
That doesn’t look quite right, that’s true. While the source code is OK, the Mime-type is not correct.
Do you send
// send the right header
header('Content-type: text/xml; charset="utf-8"');
in front of the xml, like https://getkirby.com/docs/cookbook/xmlsitemap says?
I wonder why this line is formatted as a comment
<!--?xml version="1.0" encoding="UTF-8" standalone="yes"?-->
And look at
https://forum.getkirby.com/t/sitemap-with-file-extension-xml-dosent-work/5011
e.g. at the very end!
Is it possibly i changed from https://domain.tld to https://www.domain.tld?
Don’t see why that should make a difference. Did it work before?
Yes, it did and on localhost it works right now.
I have the Condition in .htaccess to rewrite non-www to www only on the domain.
Looks like it’s working now?
So… now it works.
I dont know why, but what my code looks like:
<?php
header('Content-type: text/xml; charset="utf-8"');
$ignore = array('sitemap', 'error');
// echo the doctype
print '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<?php foreach($pages->index()->visible() as $p): ?>
<?php if(in_array($p->uri(), $ignore)) continue ?>
<url>
<loc><?= html($p->url()) ?></loc>
<lastmod><?= $p->modified('c') ?></lastmod>
<priority><?= ($p->isHomePage()) ? 1 : number_format(0.5/$p->depth(), 1) ?></priority>
</url>
<?php endforeach ?>
</urlset>
I put the header() in Line 1 and instead of “echo” the <?xml> i “print” it.
Well, glad that it works now…