Totally no parent slugs in all pages urls

Hey Kirby Folks,

I’m totally bad in writing new routes for kirby and have the following question:

What is the easiest and bulletproof way to write routes, that eliminate all slugs of all pages urls.

For example no “” and no “” just “” and “

Thanks for your help,

You can use the (:any) placeholder to catch all routes after the domain and until the next slash.

Then try to find a page with that slug.

Note that if you happen to have duplicate slugs under different parent pages, such pages wouldn’t be accessible anymore or rather, your route than would only deliver the first match, e.g. and

However, this shouldn’t be a problem if you just want your blog posts to be available without the blog bit.

The code you need would be basically like in the old Kirby 2 docs, adapted to Kirby 3:

Here is similar code for Kirby 3:

1 Like

That is totally working if I know the slug of the parent pages, but we want to have flat urls for every page.

By the way: For me it’s totally fine and logic how kirby works by default, and I think thats the way every website should, but those SEO People in my office think different :frowning:

Maybe something like:

$page = $kirby
  ->filterBy('uid', $slug)
  ->first() ?? site()->errorPage();

(Sorry, would have given a complete example, but writing code on a phone is really painful)

This obviously has to scan the whole website on every page load. Depending on the size of your website, this could be a problem for performance and, therefore, also for SEO :wink:

Note that in addition to the routes, it would also make sense to overwrite the URL method for every page to print the target URL.