How to filter a global route to exclude some specific paths

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 site()->visit($page);
    	},
 	),
));

Looks complicated, but all it does is to check if the URI is not equal to sitemap.xml. The pattern matches for any other URI.

Of course this gets pretty messy once you need to exclude multiple URIs. In this case, @texnixe’s solution is cleaner and the better solution.