Dynamic routing

I need to migrate an existing website’s url scheme to kirby. I was thinking of adding a field “full_path” in which I can enter something like some-seorified-path/for-whatever/reason in it and it can then be view at "example.com/some-seorified-path/for-whatever/reason` - no matter where in Kirby’s content-folder it is placed.

However I’m not sure how I’d define such a route.

That would be something like this:

c::set('routes', array(
    'pattern' => '(.+)',
    'action'  => function($uri) {
      $kirby = kirby();
      $site = $kirby->site();
      $page = $site->index()->findBy('fullpath', $uri)->uri();
      return $site->visit($page);

However, you would have to define the old path for every page.

If there are any rules by which you could reroute, I’d prefer to do this in the .htaccess or - if you have access to the server configuration file - in there.

Unfortunately there’s no specific rule for the old paths.

However this work:

'pattern' => '(.+)',
'action' => function($uri) {
  $index = site()->index();
  $default = $index->find($uri);
  $custom = $index->findBy('seo_path', $uri);
  $visit = ($custom)
    ? $custom
    : $default
  return site()->visit($visit->uri());

(no error handling so far, merely a proof-of-concept)

Now I just need to create a custom url method for each of the template’s model that use the seo_path if applicable. But that I know how to do :slight_smile: