No permalink for subpages

Hey there,
I couldn’t find any topic, so here goes:

If I wanted a subpage not to have an own page, how’d I accomplish that? I want to make them inaccessible via their URL, for example in the starterkit > About > Team members (them cats). It’s a nice way to think of them as child pages / subpages, but each of them gets /about/name-of-cat URL.

Hopefully somebody can explain, I’m totally willing to learn the force of Kirby,
thanks

S1SYPHOS

Every page you create in Kirby has it’s own URL, you can’t prevent that.

The best way to cope with this “problem”, is by using routes. These routes react on a certain pattern an can then reroute either to the parent or the error page. See the docs: https://getkirby.com/docs/developer-guide/advanced/routing

Example: This would reroute all children of the about page to the parent:

c::set('routes', array(
  array(
    'pattern' => 'about/(:any)',
    'action'  => function() {
       go('about');
    }
  )
));

I have used a different approach before. I created a custom page model in which I override the controller function to redirect to the parent page; then I assign the new page model to my subpage blueprints explicitly with

kirby()->set('page::model', 'my-subpage-blueprint', 'MyPageModelClass');

That way, wherever I decide to put my subpage(s), if I someone tries to access their URL directly, they get redirected to the parent page.

I use another solution similar to @texnixe with a difference.

If the site is new I see no need for a redirect in the first place. We don’t expect people to look for about/some-page anyway so I think it should just be an error 404.

c::set('routes', array(
  array(
    'pattern' => 'about/(:any)',
    'action'  => function() {
       return site()->visit('error');
    }
  )
));