texnixe
November 20, 2018, 4:32pm
4
You don’t have to create your own router, it should actually work in a standard config setting, see these two answers from the same thread for possible solutions:
This seems to work:
kirby()->routes([
[
'pattern' => '(:any)',
'action' => function($uid) {
$page = page($uid);
if(!$page) $page = page('database/' . $uid);
if(!$page) $page = site()->errorPage();
return site()->visit($page);
},
'filter' => function($route) {
if(in_array('sitemap.xml', $route->arguments())) { return false; }
},
]
]);
Filters are not really meant to restrict the pattern of the route, their main use-case is authentication and other “environment checks”.
The best way would be defining the pattern in a way that excludes the sitemap in the first place:
kirby()->routes(array(
array(
'pattern' => '^(?!sitemap\.xml$)(.*)$',
'action' => function($uid) {
$page = page($uid);
if(!$page) $page = page('database/' . $uid);
if(!$page) $page = site()->errorPage();
return…
1 Like