Multilingual site: serving homepage without language id in path

When setting up a multilingual site, Kirby routes the homepage to the main language, e. g. / routes to /de if German is the default. Following the guides at Multi-language | Kirby CMS, I can set up the url for a language to be root. This perfectly serves my default language at / but also removes the language id from all subsequent urls.

Is there a way to tell Kirby to serve the homepage in the default language at the root / directly, while still keeping the language id in the other pages urls? Like / for the German homepage but /de/projekte and /en/projects for the localized project pages.

With the url option set to /, it should work with a route like this:

  'routes' => [
    [
        'pattern' => 'en/(:all)',
        'action' => function ($path) {
           return page($path);
        },
    ],
  ],

This is just the basic code. You need some checks here, if the page exists and if not return the error page, etc.

If you use this route, you have to also make sure to prevent duplicate content being served at both URLs (with and without the lang code)

I’ll try that out. Thanks!

I’d like to do the same but it seems quite cumbersome. What’s the reason in the first place to change this with v3?

Trying to remember here: Was that not the same in v2?

I think so, yes. The language code was either anywhere or nowhere.

Exactly - it was either there all the time ot not, right?
But isn’t this post about not having it only on home, but having it on all other pages?

Yes, exactly. That wasn’t possible in Kirby 2 without rerouting, either.

@nilshoerrmann, @mrflix What are your reasons for having the code anywhere but not on the homepage? If you use the language code to provide more information to users, it would make sense on the homepage as well.

The language code of the primary language was not rendered in the URL in v2. Take for example this page using Kirby v2:

Startpage
DE: studiocoucou.berlin
EN: studiocoucou.berlin/en

Subpage
DE: studiocoucou.berlin/produkte
EN: studiocoucou.berlin/en/products

That’s the behavior I’m missing. Having mono.de redirect to mono.de/de doesn’t look very sexy.

Yes, but that is no different from how Kirby 3 works. See @nilshoerrmann suggestion above.

The use case @nilshoerrmann describes is different from what you describe. He want the homepage without the code, but all other page with code.

I think you can do this already by setting 'url' => '/' in your language file, see https://getkirby.com/docs/guide/languages/introduction#language-specific-urls.

Exactly.

I like the idea of having language codes for all languages because the user directly sees in the URL that this is localised content. But I don’t like the idea of having hananils.de/de which is just doubling the language code. (I know this is still the case for links to subpages but to me the context is different.)

But I have to say that this problem not very important to me. So I’m not going to “work against Kirby” here to force my own URL concept. The two possible schemes follow a logical concept, so that’s fine.

Well, maybe it doesn’t look so cool for de domains (it doesn’t really duplicate the language code), but this is more a cosmetic problem which you can solve with routes if you really need to.

Yes, exactly. I just edited my comment above and added:

But I have to say that this problem not very important to me. So I’m not going to “work against Kirby” here to force my own URL concept. The two possible schemes follow a logical concept, so that’s fine.

1 Like

“Cosmetic problem” is a good description.

@mrflix: In Kirby 2, you had to set the default language URL to / to get rid of the language code. It’s the same for Kirby 3. Unless I’m misunderstanding something, then there shouldn’t be any problem.