Getting 404 error when accessing site map. Possible config.php error

Hi I added a site map to my website after following this tutorial: Sitemap for search engines | Kirby CMS. However when I go to mydomain.com/sitemap as advised at the bottom here I get a 404 error. I have also set cache to not active in this same file and this does not work either so I am under the impression this file has not been written correctly.

<?php
return [
    'debug'  => true
];

c::set('routes', array(
  array(
    // in 'pattern', enter the same url being called from your ajax javascript function
    'pattern' => '.../templates/contact.php',
    'method' => 'POST',
    'action' => function() {
      // check whether this is an ajax request, and respond with an error if it isn't
      if(!kirby()->request()->ajax()){ return response::error("Page Not Found!","404");}
      // process the form data, send the email - and get the result (as an array)
      $data = mailFormData(kirby()->request()->data());
      // respond with the result - in JSON format
      return response::json($data);
      }
    )
));

return [
  'cache' => [
      'pages' => [
          'active' => false,
          'ignore' => function ($page) {
            return $page->title()->value() === 'Do not cache me';
          }
      ]
  ]
];

return [
  'smartypants' => true
];

return [
  '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']);

          $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);
      }
    ]
  ]
];

c::set is Kirby 2 syntax and you should not have multiple return statements in your config, everything after the first return will be ignored.

https://www.php.net/manual/en/function.return.php

Hi So effectively if I put all the returns in the same return it will be okay?

I get errors with this:

<?php
return [
    'debug'  => true,
    'cache' => [
      'pages' => [
          'active' => false,
          'ignore' => function ($page) {
            return $page->title()->value() === 'Do not cache me';
          }
      ]
  ]
  'smartypants' => true
  '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']);

          $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);
      }
    ]
  ]
];

c::set('routes', array(
  array(
    // in 'pattern', enter the same url being called from your ajax javascript function
    'pattern' => '.../templates/contact.php',
    'method' => 'POST',
    'action' => function() {
      // check whether this is an ajax request, and respond with an error if it isn't
      if(!kirby()->request()->ajax()){ return response::error("Page Not Found!","404");}
      // process the form data, send the email - and get the result (as an array)
      $data = mailFormData(kirby()->request()->data());
      // respond with the result - in JSON format
      return response::json($data);
      }
    )
));

You have to put a comma after each item in an array in PHP

Yes this worked, thank you so much for the help