Language-specific domain not switching to the correct language

Hello!

I’m trying to use two domains for my site’s two languages:

www.escape-team.com - en
www.escape-team.de - de

However, going to

will not show the German language site.

Here’s my de.php:


<?php

return [
    'code' => 'de',
    'default' => false,
    'direction' => 'ltr',
    'locale' => [
        'LC_ALL' => 'de_DE'
    ],
    'name' => 'Deutsch',
    'translations' => [
    'minutes' => ' Minuten',
    'printnow' => 'JETZT AUSDRUCKEN',
    ],
    'url' => 'https://www.escape-team.de'
];

This is my en.php:

<?php

return [
    'code' => 'en',
    'default' => true,
    'direction' => 'ltr',
    'locale' => [
        'en_US'
    ],
    'name' => 'English',
    'translations' => [
        'minutes' => ' min.',
        'printnow' => 'PRINT NOW'
    ],
    'url' => 'https://www.escape-team.com'
];



This is my config.php:

<?php

return [

    'smartypants' => true,
    'debug' => true,


    'date'  => [
      'handler' => 'strftime'
    ],

    'languages.detect' => false,
    'languages' => true,

    // Autoresize
    'medienbaecker.autoresize.maxWidth' => 1920,

    // Cachebuster
    'schnti.cachebuster.active' => true,

    // Commentions
    'sgkirby.commentions.templatesWithComments' => ['article'],
    'sgkirby.commentions.templatesWithWebmentions' => [''],
    'sgkirby.commentions.hideforms' => false, /* Comment form hide buttom, if true */
    'sgkirby.commentions.expand' => true, /* Webmention form hide buttom, if true */
    'sgkirby.commentions.allowlinks' => true, /* Allow links in comments, if true */
    'sgkirby.commentions.autolinks' => true,  /* Automatically recognize URLs in comments and turn them into links. Has no effect, if allowlinks is false. */
    'sgkirby.commentions.commentfields' => [
      'name' => true,  // include name field and mark as required
      'email'=> true,  // include email as optional field
      'website',       // include optional website field
    ],
    'sgkirby.commentions.secret' => '<YOUR-SECRET>', // A valid secret key must be at least 10 characters long and may NOT include any of the following: & % # + nor a space sign .

    // Srcset
    'thumbs' => [
      'quality' => '85',
      'srcsets' => [
        'default' => [    
          '800w' => [
          'width' => 800
        ], 
          '1024w' => [
            'width' => 1024
        ], 
          '1920w' => [
            'width' => 1920
        ], 
        ],
      ]
    ],

    // Robots  
    'bnomei.robots-txt.sitemap' => 'sitemap.xml',
    'bnomei.robots-txt.groups' => [ // array or callback
      '*' => [ // user-agent
          'disallow' => [
              '/kirby/',
              '/site/',
          ],
          'allow' => [
              '/media/',
          ]
      ]
    ],

    // Support for language detect option
    'routes' => [
      [
          'pattern' => '/',
          'action'  => function () {
              $session = kirby()->session();
            
              if ($session->get('languages.detect', false) === false && option('languages.detect') === true) {
                  $session->set('languages.detect', true);
                  
                  return kirby()
                      ->response()
                      ->redirect(kirby()->detectedLanguage()->url());
              }
              
              return page();
            }
        ]
    ]
      
];

This is my .htaccess:

# Apache block users from browsing folders without a default document
<IfModule mod_autoindex.c>
  Options -Indexes
</IfModule>

# Kirby .htaccess

# rewrite rules
<IfModule mod_rewrite.c>

# enable awesome urls. i.e.:
# http://yourdomain.com/about-us/team
RewriteEngine on

# make sure to set the RewriteBase correctly
# if you are running the site in a subfolder.
# Otherwise links or the entire site will break.
#
# If your homepage is http://yourdomain.com/mysite
# Set the RewriteBase to:
#
# RewriteBase /mysite

# In some environments it's necessary to
# set the RewriteBase to:
#
# RewriteBase /

# Cachebuster plugin
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.(\d+)\.(js|css)$ $1.$3 [L]

# block files and folders beginning with a dot, such as .git
# except for the .well-known folder, which is used for Let's Encrypt and security.txt
RewriteRule (^|/)\.(?!well-known\/) index.php [L]

# block text files in the content folder from being accessed directly
RewriteRule ^content/(.*)\.(txt|md|mdown)$ index.php [L]

# block all files in the site folder from being accessed directly
# except for requests to plugin assets files
RewriteRule ^site/(.*) index.php [L]

# Enable authentication header
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

# block direct access to kirby and the panel sources
RewriteRule ^kirby/(.*) index.php [L]

# make site links work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [L]

</IfModule>

# compress text file responses
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/json
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>

Any thoughts would be appreciated! Thank you!

—Fabian

(I went on to fix it by adding


<?php
return function($kirby, $site, $pages, $page) {

if(strpos($_SERVER['HTTP_HOST'],"escape-team.de")!==false)  {
    $kirby->setCurrentLanguage("de");
}

to my site.php controller – but it feels like that’s not the way it’s meant to be :wink: )

(Also, this way the translations from the [language].php file don’t work – you can see that on my German site, it still reads ‘print now’.)

Any help is appreciated! Thank you!

In your config file, the languages.detect option is set to false. Or do you have a second config where this option is set to true?

I wasn’t aware of that option being enabled, but it was! I removed that piece of code, now it doesn’t detect (and overwrite) my language anymore. Thank you!