Routes pattern for multilanguage site

Hello everyone, I’m trying to set up a route but I can’t make work the same pattern for multisite urls. Here is the code:

  'pattern' => '(:any)/download/([a-f0-9]{32})',
  'action' => function($page_uri, $hash) {
       if ($file = page($page_uri)->files()->findBy('hash', $hash)) {
           $filename = $file->url();
               return go($filename);
    return go('/');

This works fine for a default language url like[hash] but it doesn’t work for a url like[hash].
I’ve tried adding another placeholder for the language but since my default language url doesn’t contains /en for instance it doesn’t work.
Any ideas on how to solve this?

It’s probably easiest to use two routes, one with language code, one without. Or you have to check for the language code. Use search to find some examples here on the forum.

I will follow your advice and use two different routes.

Something like this should work too.
Looks ugly but gets the job done :wink:

$kirby->set('route', [
  'pattern' => '(?:(^[A-Za-z]{2})//?)?(:any)/download/([a-f0-9]{32})',
  'action'  => function($lang, $page_uri, $hash) {
    $lang = $lang ?: 'en'; // the default language
    // do stuff

Thank you I will try it