# Redirect top-level pages to first subpage

**URL:** <https://forum.getkirby.com/t/redirect-top-level-pages-to-first-subpage/3440>\
**Category:** Questions\
**Tags:** v2\
**Created:** [February 26, 2016, 2:15pm UTC](https://forum.getkirby.com/t/redirect-top-level-pages-to-first-subpage/3440 "2016-02-26T14:15:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![trollverk](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/trollverk/32/1721_2.png) [@trollverk](https://forum.getkirby.com/u/trollverk)\
**Post date:** [February 26, 2016, 2:15pm UTC](https://forum.getkirby.com/t/redirect-top-level-pages-to-first-subpage/3440/1 "2016-02-26T14:15:39Z")

</div>

Hi all!

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

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.

**Example:**

Structure of folders in content:

/1-home  
/2-test1  
– 1-test1-sub1  
– 2-test1-sub2  
– etc.  
/3-test2  
– 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?

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [February 26, 2016, 2:22pm UTC](https://forum.getkirby.com/t/redirect-top-level-pages-to-first-subpage/3440/2 "2016-02-26T14:22:00Z")

</div>

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:

```nohighlight
(:any)

```

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](https://getkirby.com/docs/advanced/routing#omitting-the-blog-folder-in-urls) as an example. In your case, you would check if the page has a subpage and redirect to the first one if it does.

---

<div class="post-metadata">

**Author:** ![trollverk](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/trollverk/32/1721_2.png) [@trollverk](https://forum.getkirby.com/u/trollverk)\
**Post date:** [February 26, 2016, 3:38pm UTC](https://forum.getkirby.com/t/redirect-top-level-pages-to-first-subpage/3440/3 "2016-02-26T15:38:34Z")

</div>

Thank you, Lukas.

It works like a charm. 🙂

---

<div class="post-metadata">

**Author:** ![flokosiol](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/flokosiol/32/468_2.png) [@flokosiol](https://forum.getkirby.com/u/flokosiol)\
**Post date:** [February 26, 2016, 8:15pm UTC](https://forum.getkirby.com/t/redirect-top-level-pages-to-first-subpage/3440/4 "2016-02-26T20:15:13Z")

</div>

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

> [@Editable page redirects](https://forum.getkirby.com/t/editable-page-redirects/988):
>
> ###Why do I need editable page redirects? You wat to create a menu item which redirects to its first child You want to have an easy to remember url which links to an existing page You want to have redirects which can be edited by editors within the panel Creating editable page redirects with Kirby is really easy … ###Step 1: Blueprint site/blueprints/redirect.php title: Redirect pages: true files: false fields: title: label: Title type: text redirect: label: Redirect to pa…

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:00pm UTC](https://forum.getkirby.com/t/redirect-top-level-pages-to-first-subpage/3440/5 "2025-02-06T17:00:08Z")

</div>

Archived on February 6, 2025, 5:00pm UTC


