# Routing for Virtual Profile Pages

**URL:** <https://forum.getkirby.com/t/routing-for-virtual-profile-pages/21625>\
**Category:** Questions\
**Tags:** v3\
**Created:** [March 16, 2021, 2:43pm UTC](https://forum.getkirby.com/t/routing-for-virtual-profile-pages/21625 "2021-03-16T14:43:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![timhartmann](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/timhartmann/32/9577_2.png) [@timhartmann](https://forum.getkirby.com/u/timhartmann)\
**Post date:** [March 16, 2021, 2:43pm UTC](https://forum.getkirby.com/t/routing-for-virtual-profile-pages/21625/1 "2021-03-16T14:43:12Z")

</div>

I would like to change the routing a bit. I create a separate virtual page for each user. This is accessible under **/profile/USERID**. However, I would like to make this accessible under **/profile/USERNAME/USERID/.**

However, if the user changes the user name, the same profile should still be accessed.

Possible urls can be, if the user change his name:  
/profil/tim/14KHeYF5  
/profil/timhartmann/14KHeYF5

There should be no difference, because the same page is called up on the basis of the ID without throwing an error.

Do you have an idea how to solve this? I am at a loss after many attempts.

**models/profile.php**

```
<?php

class ProfilePage extends Page
{
  public function children()
  {
    $usersPages = [];
    $users = kirby()->users();
    $currentUser = kirby()->auth()->currentUserFromSession();
    $isCurrentUser;
    foreach ($users as $key => $user) {
      
      if($currentUser == $user->id()) {
        $isCurrentUser = true;
      } else {
        $isCurrentUser = false;
      }
      $userPages[] = [
        'slug' => Str::slug($user->id()), // or username if unique
        'num' => $user->indexOf($users),
        'template' => 'profile',
        'model' => 'profile',
        'content' => [
          'title' => $user->username(),
          'user' => $user,
          'currentUser' => $currentUser,
          'isCurrentUser' => $isCurrentUser,
          'position' => $user->position(),
          'bio' => $user->bio()
        ]
      ];
    }
    return Pages::factory($userPages, $this);

  }
}
```

---

<div class="post-metadata">

**Author:** ![pixelijn](https://avatars.discourse-cdn.com/v4/letter/p/7ab992/32.png) [@pixelijn](https://forum.getkirby.com/u/pixelijn)\
**Post date:** [March 16, 2021, 4:56pm UTC](https://forum.getkirby.com/t/routing-for-virtual-profile-pages/21625/2 "2021-03-16T16:56:31Z")

</div>

If you want the pages to be accessible under a different URL you need to create a route that listens to the new pattern and a model for the single user page with a redefined URL method.

On a side note, you can also get the currently logged-in user with `kirby()->user()`

---

<div class="post-metadata">

**Author:** ![timhartmann](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/timhartmann/32/9577_2.png) [@timhartmann](https://forum.getkirby.com/u/timhartmann)\
**Post date:** [March 16, 2021, 6:20pm UTC](https://forum.getkirby.com/t/routing-for-virtual-profile-pages/21625/3 "2021-03-16T18:20:37Z")

</div>

I am very grateful that you always try to help. Unfortunately, the proposal doesn’t make it very clear to me what to do. After all, I already have a model that creates pages. I suspect that I have to do something with the routing in the config.

---

<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:** [March 16, 2021, 6:38pm UTC](https://forum.getkirby.com/t/routing-for-virtual-profile-pages/21625/4 "2021-03-16T18:38:12Z")

</div>

> [@timhartmann](#):
>
> After all, I already have a model that creates pages.

You model is a model for the parent and creates the virtual subpages, yes. So these virtual subpages are accessible via their standard route `yourdomain.com/profile/userid`.

If you want to change this route, you need a route (in your config, a plugin).

> **[Routing](https://getkirby.com/docs/guide/routing)**
>
> Use Kirby's router to modify URLs or provide extra functionality when the user calls an given URI pattern.

An as already mentioned above, you will want to override the `url` method in the method for the profile pages (unfortunately, you use are using the same model for the children (profile) as for the parent, which doesn’t make sense.

The children method belong in the parent page (profile), then you need a second template/model/blueprint for the children.
