Create custom routes from text field or structure

Hi, I want my customer to be able to edit some short urls, like this.

Link: /short
Redirect to: /some/url/on/the/page

The retour plugin is currently unavailable for that, so I figured the easiest way would be to add a field to each page and create a custom route. (as discussed here: Manually choose tinyurl slug? - #7 by fitzage)

    [
      'pattern' => '/go/(:all)',
      'action'  => function ($slug) {
        $page = site()->index()->findBy('shortlink', $slug);
        go($page ? $page->url() : 'error');
      }
    ]

This works, but is there any way to create a custom route without having some kind of prefix?
How would I do that?

Alternatively it could also be a central structure field with shortlinks that would be called before any other call - but I’m not sure how to do that…

Maybe this can help: Routing | Kirby CMS

1 Like

That helps indeed!
Thank you :slight_smile: