Routing: how to remove language id from url?

Hi, I have a multi-language site in need of some url shortening. I tried to get rid of the language bit by following the routing instructions and tried different versions of this following thing in the config.php, but with no luck. What is wrong?

return [
  'routes' => [
	[
	'pattern' => 'http://mysite.com/asiat',
	'action'  => function () {
		return site()->visit('mysite/asiat', 'fi');
		}
	],
	[
	'pattern' => 'http://mysite.com/things',
	'action'  => function () {
		return site()->visit('mysite/asiat', 'en');
	}
	]
  ]
];

kirby does routing based on your language. i do not think you can disable that fully but you can

having the code in url also helps with defining canonical url and proper alt-links for SEO. https://github.com/pedroborges/kirby-meta-tags#link

Thanks for your reply.

I guess I wrote a bit too broadly. I don’t need a universal solution to this, just two short urls, one for each of the two language versions of a certain page.

I wouldn’t want to use different domains and neither would I want to get rid of the default language code in general.

Is it really so that it isn’t possible to route two different urls (they can be hardcoded, if that matters) to the different language versions of the same page?

i gave your code a quick spin in a multilanguage setup and for me it worked but i had to remove the domain in the pattern 'pattern' => 'asiat',.

Sometimes, you don’t see the wood for the trees :see_no_evil:

1 Like