Invalid page object

Hello all!

I tweaked this code from the Kirby site, to redirect pages in the rhymes/ folder.


  'routes' => [

    [
        'pattern' => '(:any)',
        'action'  => function($uid) {
            $page = page($uid);
            if(!$page) $page = page('rhymes/' . $uid);
            if(!$page) $page = site()->errorPage();
            return site()->visit($page);
        }
    ],
    [
        'pattern' => 'rhymes/(:any)',
        'action'  => function($uid) {
            go($uid);
        }
    ],
    [
      'pattern' => '(:any)',
      'action'  => function($uid) {
          $page = page($uid);
          if ($page instanceof Page === false) go('https://google.com');
      }
    ],
  ]

Which works fine, but now Kirby does not redirect anymore on an error.
I add the last bit, bu t it does not work yet.
It is not even loading the template as the error occurs before that.
In the template:

<?php 
	if($page->title() == 'error' ) {
		go($site->homePage(), 301); 
	}
?>

Any ideas? Thanks!!

This shouldn’t be there…

No you are right. Its my humble attempt to make it work. Google is just a placeholder for a url. What should be there?

Nothing, don’t overwrite your first route.

Oh, and one more thing: Why are you doing this? An error page should not point to the home page…

Well that’s something that can work within a certain context.
The problem is, that when I type in a url for in a page that does not exist,
this error comes up, where it should redirect to the error page.
How can I fix that?