# Incorrect header::contentType on sitemap

**URL:** <https://forum.getkirby.com/t/incorrect-header-contenttype-on-sitemap/12523>\
**Category:** Questions\
**Tags:** v3\
**Created:** [January 28, 2019, 8:21pm UTC](https://forum.getkirby.com/t/incorrect-header-contenttype-on-sitemap/12523 "2019-01-28T20:21:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![myles-w](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@myles-w](https://forum.getkirby.com/u/myles-w)\
**Post date:** [January 28, 2019, 8:21pm UTC](https://forum.getkirby.com/t/incorrect-header-contenttype-on-sitemap/12523/1 "2019-01-28T20:21:50Z")

</div>

Hi,

I’ve been putting together a small test site to play with Kirby 3. As part of this I wanted to generate an automatic sitemap so I followed the instructions here:

[https://getkirby.com/docs/cookbook/seo/xmlsitemap](https://getkirby.com/docs/cookbook/seo/xmlsitemap)

I think I’ve followed everything correctly, however when I run a validation check on the sitemap using the xml-sitemap’s checker I get an error of:

Incorrect http header content-type: “text/html; charset=UTF-8” (expected: “application/xml”)

To check what I’ve done, I have a snippet in site/snippets called sitemap.php:

```
<?= '<?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') ?></lastmod>
            <priority><?= ($p->isHomePage()) ? 1 : number_format(0.5 / $p->depth(), 1) ?></priority>
        </url>
    <?php endforeach ?>
</urlset>

```

and in site/config/config.php I have:

```
'sitemap.ignore' => ['error'],
'routes' => [
  [
'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');

    // set the correct header type
    header::contentType('text/xml', 'UTF-8', true);

    return snippet('sitemap', compact('pages', 'ignore'), true);
}
  ],
  [
'pattern' => 'sitemap',
'action' => function() {
  return go('sitemap.xml', 301);
}
  ]
],

```

and the HTML generated is:

```
<?xml version="1.0" encoding="utf-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
                            <url>
            <loc>*website url*</loc>
            <lastmod>2019-01-17T19:04:41+00:00</lastmod>
            <priority>1</priority>
        </url>
    </urlset>

```

The generated HTML looks correct, so I think the problem is the header::contentType isn’t being set correctly by the config file.

Can anyone help me see where I’m going wrong?

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [January 29, 2019, 6:45am UTC](https://forum.getkirby.com/t/incorrect-header-contenttype-on-sitemap/12523/2 "2019-01-29T06:45:20Z")

</div>

you need to use a new way to send headers in kirby3.

> [@Sending custom status headers](https://forum.getkirby.com/t/sending-custom-status-headers/12506/6):
>
> I just remembered a change during the latest K3 betas. Bastian posted on Slack: In order to fix this once and for all I’ve come up with a way to configure the response in your controllers or templates and cache that configuration with the page. This new implementation has a lot of nice side effects. Here’s how it looks like in a controller for example if you want to change the content type, the response code and set some headers. $kirby -\>response() -\>code(202) -\>type('rss') …

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [January 29, 2019, 6:48am UTC](https://forum.getkirby.com/t/incorrect-header-contenttype-on-sitemap/12523/3 "2019-01-29T06:48:11Z")

</div>

also a plugin exists for sitemaps if you need a ready-to-use solution.

> **[omz13/kirby3-xmlsitemap](https://github.com/omz13/kirby3-xmlsitemap)**
>
> kirby3 plugin to generate an xml-based sitemap. Contribute to omz13/kirby3-xmlsitemap development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![myles-w](https://avatars.discourse-cdn.com/v4/letter/m/96bed5/32.png) [@myles-w](https://forum.getkirby.com/u/myles-w)\
**Post date:** [January 29, 2019, 4:02pm UTC](https://forum.getkirby.com/t/incorrect-header-contenttype-on-sitemap/12523/4 "2019-01-29T16:02:42Z")

</div>

Hi,

The instruction I’m using to set the header content type is the same as in the cookbook article on sitemaps which I would have thought would be right? I’ll have a look at the forum post you linked to and try that.

Thanks,

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [January 29, 2019, 4:08pm UTC](https://forum.getkirby.com/t/incorrect-header-contenttype-on-sitemap/12523/5 "2019-01-29T16:08:01Z")

</div>

i see. as far i know her @texnixe has read this already, she will check the cookbook example and fix it if needed.
