Redirect top-level pages to first subpage

Hi all!

I am working on my first Kirby-project. So far, I like the system. :smile:

A small problem concerning rerouting pages recently popped up

Coming from TYPO3 where you can just select to which page a page entry should reroute, I wonder if there is an easy way to reroute a page to the first subpage in a folder.


Structure of folders in content:

– 1-test1-sub1
– 2-test1-sub2
– etc.
– 1-test2-sub1
– 2-test2-sub2
– etc.

E.g. domain.tld/test1 should reroute to domain.tld/test1/test1-sub1 and domain.tld/test2 to domain.tld/test2/test2-sub1_

I already know about the router code you can add to config.php. Do I really have to manually set up all possible routes in the config-file?

The route patterns use regular expressions that are extended with some shortcut placeholders. You can for example use the following patterns to match every top-level page:


Your route action will then get passed that value as the first parameter. You can use the first route in the omitting the blog folder example as an example. In your case, you would check if the page has a subpage and redirect to the first one if it does.

1 Like

Thank you, Lukas.

It works like a charm. :slight_smile:

I know that the following topic is not what you’re asking for, but maybe it’s interesting for you, too.

1 Like