Help with Error-Routing

routes

#1

Heyho,
I re-route my error pages not to an specific error-page but my home-page with appended data with indicates the error. I got nearly everything to work. The following links successfully route to error pages:

  • site.com/blablabla
  • site.com/items/blablabla
  • site.com/items/blablabla/blablabla

The only type of links which deliver only a blank page and don’t route to the error are:

  • site.com/blabla/blabla

I’ve appended my router-code. I already tried to replace the (:any) in the first route with (:all) but then not even site.com/blablabla displays an error but only a blank page :frowning:

c::set('routes', [

  // - Redirect 'items/' to the root '/'
  // - Send error-page to home with appended data
  [
    'pattern' => '(:any)',
    'action'  => function($uid)
    {
      $page = page($uid);

      if ($uid == 'items') go('/');
      if ($page) return site()->visit($page);

      return ['/home', ['error' => $uid]];
    }
  ],

  // Redirect external-link items to their destination
  [
    'pattern' => 'items/(:all)',
    'action'  => function($uid)
    {
      $page = page("items/${uid}");

      if ($page && $page->isExternalLink()) go($page->externalLink());
      if ($page) return site()->visit($page);

      return ['/home', ['error' => "items/${uid}"]];
    }
  ]

]);

Thanks as always!


#2

I think that is some sort of weird bug, it should work with this pattern:

'pattern' => '(:any)(:all)',

#3

I really appreciate your crazy fast support and always accurate answers. It works now :wink:

Would you file an issue for that?


#4

I think there is already an issue on GitHub, will check that.

Yes, here: https://github.com/getkirby/kirby/issues/368