# Remove parent page name in subpage url

**URL:** <https://forum.getkirby.com/t/remove-parent-page-name-in-subpage-url/11013>\
**Category:** Questions\
**Tags:** v2\
**Created:** [August 10, 2018, 10:05am UTC](https://forum.getkirby.com/t/remove-parent-page-name-in-subpage-url/11013 "2018-08-10T10:05:50Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![jciaurriz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jciaurriz/32/5480_2.png) [@jciaurriz](https://forum.getkirby.com/u/jciaurriz)\
**Post date:** [August 10, 2018, 10:05am UTC](https://forum.getkirby.com/t/remove-parent-page-name-in-subpage-url/11013/1 "2018-08-10T10:05:50Z")

</div>

Hi everyone,

I want to remove in a url of a subpage the name of the its parent page. I’ll give an example:

I have this:

> **[Home Page](https://www.page.com/)**
>
> PageGroup Changes Lives for People through Creating Opportunity to Reach Potential

I want this:

> **[Home Page](https://www.page.com)**
>
> PageGroup Changes Lives for People through Creating Opportunity to Reach Potential

How can I do this? I’ve tried with routes but I can’t .

Thank you 🙂

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [August 10, 2018, 10:21am UTC](https://forum.getkirby.com/t/remove-parent-page-name-in-subpage-url/11013/2 "2018-08-10T10:21:44Z")

</div>

You have to do two things:

1. If you want to link to these pages, you have to change the `url()`method for these pages. using. a. Page Model
2. You have to implement a route similar to [Omitting the blog folder in URLs](https://getkirby.com/docs/developer-guide/advanced/routing#omitting-the-blog-folder-in-urls), only one level. deeper down.

This. should. work:

```auto
c::set('routes', array(
  array(
    'pattern' => 'news/(:any)',
    'action' => function($uid) {

      $page = page('news/'.$uid);

      if(!$page) $page = page('news/category' . $uid);
      if(!$page) $page = site()->errorPage();

      return site()->visit($page);

    }
  ),
  array(
    'pattern' => 'news/category/(:any)',
    'action' => function($uid) {
      go('news/'.$uid);
    }
  )
));

```

---

<div class="post-metadata">

**Author:** ![jciaurriz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jciaurriz/32/5480_2.png) [@jciaurriz](https://forum.getkirby.com/u/jciaurriz)\
**Post date:** [August 10, 2018, 10:43am UTC](https://forum.getkirby.com/t/remove-parent-page-name-in-subpage-url/11013/3 "2018-08-10T10:43:06Z")

</div>

Hi, thanks. But my problem is that /category is not the name of the page, it has a custom name. for example:

news/my-custom-category/my-new

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [August 10, 2018, 10:48am UTC](https://forum.getkirby.com/t/remove-parent-page-name-in-subpage-url/11013/4 "2018-08-10T10:48:38Z")

</div>

How many categories are there and are they dynamic or fixed?

---

<div class="post-metadata">

**Author:** ![jciaurriz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jciaurriz/32/5480_2.png) [@jciaurriz](https://forum.getkirby.com/u/jciaurriz)\
**Post date:** [August 10, 2018, 10:50am UTC](https://forum.getkirby.com/t/remove-parent-page-name-in-subpage-url/11013/5 "2018-08-10T10:50:00Z")

</div>

They are dinamic. Now I have four but the client can create any number of them.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [August 10, 2018, 11:07am UTC](https://forum.getkirby.com/t/remove-parent-page-name-in-subpage-url/11013/6 "2018-08-10T11:07:15Z")

</div>

And what about the category pages themselves, should they still be accessible, because they display their corresponding subpages, or are they just containers?

---

<div class="post-metadata">

**Author:** ![jciaurriz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jciaurriz/32/5480_2.png) [@jciaurriz](https://forum.getkirby.com/u/jciaurriz)\
**Post date:** [August 10, 2018, 11:09am UTC](https://forum.getkirby.com/t/remove-parent-page-name-in-subpage-url/11013/7 "2018-08-10T11:09:06Z")

</div>

They are only container to organize the news.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [August 10, 2018, 11:28am UTC](https://forum.getkirby.com/t/remove-parent-page-name-in-subpage-url/11013/8 "2018-08-10T11:28:56Z")

</div>

Don’t know if. this is the best way to go about this, but try:

```auto
c::set('routes', array(
  array(
    'pattern' => 'blog/(:any)',
    'action' => function($uid) {

      if($page = page('blog/'.$uid)) {
        go($page->parent());
      } else {

        $categories = page('blog')->children()->pluck('uri', ',');
        $i = 0;

        while($i < count($categories)) {
          if($page = page($categories[$i].'/'.$uid)) {
            return site()->visit($page);
          }
             $i++;
        }
      }

          return false;

    }
  ),
  array(
    'pattern' => 'blog/(:any)/(:any)',
    'action' => function($cat, $uid) {
      go('blog/'.$uid);
    }
  )
));

```

BTW. When a topic is solved, could you please either let u. know and/or mark it as solved? There are quite a few of your questions here where I’m not sure if I can close them or not.

Edit: In the above, you have to replace `blog` of course…

---

<div class="post-metadata">

**Author:** ![jciaurriz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jciaurriz/32/5480_2.png) [@jciaurriz](https://forum.getkirby.com/u/jciaurriz)\
**Post date:** [August 10, 2018, 12:16pm UTC](https://forum.getkirby.com/t/remove-parent-page-name-in-subpage-url/11013/9 "2018-08-10T12:16:01Z")

</div>

Ah sorry, I will close them. This I didn’t resolve yet. Thanks and sorry

---

<div class="post-metadata">

**Author:** ![pedroborges](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/pedroborges/32/7038_2.png) [@pedroborges](https://forum.getkirby.com/u/pedroborges)\
**Post date:** [August 11, 2018, 12:50am UTC](https://forum.getkirby.com/t/remove-parent-page-name-in-subpage-url/11013/10 "2018-08-11T00:50:36Z")

</div>

@jciaurriz continuing from @texnixe first solution, I recommend trying this:

```php
c::set('routes', array(
  array(
    'pattern' => 'news/(:any)',
    'action' => function($uid) {
      $page = page('news/' . $uid);

      if(!$page) $page = page('news')->grandChildren()->findBy('uid', $uid);
      if(!$page) $page = site()->errorPage();

      return site()->visit($page);

    }
  ),
  array(
    'pattern' => 'news/category/(:any)',
    'action' => function($uid) {
      go('news/'.$uid);
    }
  )
));

```

By using `grandChildren` it will look for pages 2 levels down from `news`. The first level could be `category` or anything else.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [August 11, 2018, 8:32am UTC](https://forum.getkirby.com/t/remove-parent-page-name-in-subpage-url/11013/11 "2018-08-11T08:32:02Z")

</div>

Oh my, what can I say?

---

<div class="post-metadata">

**Author:** ![jciaurriz](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jciaurriz/32/5480_2.png) [@jciaurriz](https://forum.getkirby.com/u/jciaurriz)\
**Post date:** [October 31, 2018, 8:21am UTC](https://forum.getkirby.com/t/remove-parent-page-name-in-subpage-url/11013/12 "2018-10-31T08:21:49Z")

</div>

Hi,

I tried this solution and it works but when the page is multilanguage I have a problem. I’ll show an example:

A new with this url ([https://mysite.site/es/news/category/new](https://mysite.site/es/news/category/new)) can change with the code you said me ([https://mysite.site/es/news/new](https://mysite.site/es/news/new))  
But when my page is setted to French [https://mysite.site/fr/news/category/new](https://mysite.site/fr/news/category/new) it doesn’t run, 404 page appears. I think the problem is the name of the category that in french changes.

I wrote your code for each language that has my page and the only language that doesn’t run is french (the other ones are variations of Spanish and the names of the categories don’t change)

---

<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:25pm UTC](https://forum.getkirby.com/t/remove-parent-page-name-in-subpage-url/11013/13 "2025-02-06T17:25:53Z")

</div>


