Change part of URL wit multiple languages

Hi there. I just start exploring Kirby and so far I really love it, but… :smiley:
I’m stuck on a really basic thing (i suppose). I think I’ve must understand something wrong.
To the point. I have multilanguage site with folder ‘pages’ which include basic pages like ‘about’ and ‘contact’. That’s give me urls eg ‘en/pages/about’ and ‘de/pages/about’. I would like to remove ‚pages’ part and leave only ‘en/about’ and ‚‘de/about’. I read the docs and the forum, but answers i found there doesn’t work, or partially work, or like I said earlier, my understending is wrong :smiley: I thought that if i change url method in model to:

public function url($options = null): string 
{
    return $this->kirby()->url('base') . '/' . $this->slug();
}

it change url on the front side, but it changed only url of a button to preview page.
On the other hand, when i try to change url’s via config.php using

'routes' => [
    [
        'pattern' => '(:any)',
        'action'  => function($uid) {
            $page = page($uid);
            if(!$page) $page = page('pages/' . $uid);
            if(!$page) $page = site()->errorPage();
            return site()->visit($page);
        }
    ],
    [
        'pattern' => 'pages/(:any)',
        'action'  => function($uid) {
            go($uid);
        }
    ]
]

it’s not working proper with languages and not changing the preview button url.

Does it mean that, urls on the website can only be changed via config file or am i doing something wrong?
Can you help me with that?

Hi there and welcome to the Kirby forum!

May I ask why you put those pages into a subfolder in the first place? It just seems to complicate things for little to no win?

As regards the routes, yes, they are needed here. In a multilang context they work a little differently, and you better use the language scope, see http://getkirby.test/docs/guide/routing#multi-language-setup__language-scope.

Additionally, to prevent the reroute, each page type should have a model in which you overwrite the url() method to the target URL.

Thanks for reply! That make sense :wink:

As for pages subfolder. My site will have a lot of different folders (in my head custom post types - i’m still thinking in a wordpress way :confounded: ). So i create pages folder which has only static pages just to keep order in panel.

But even if I don’t keep pages in a folder, it’s nice to know how to do it just in case :wink:

In the Panel, you can achieve this via sections (filtered by template), so it’s probably not necessary to create parent pages just for the sake of grouping them in the Panel.

After all, if that leads to lot of models to prevent the rerouting, then you don’t really win. Just something to consider.

That’s what i will do, thanks for help