Weird problem with custom language url's

Hi,

I’m having this weird problem with multi language url’s (so sitename.com vs sitename.be for example). Kirby always loads the default url no matter what I set up in the config or language files. Although on my localhost it works perfectly.

So when i visit sitename.be the url in the browser is sitename.be but Kirby detects it as sitename.com when I use url() and the $kirby->language() still gives the language from sitename.com instead of sitename.be.

I would think it has to do with the way the url gets passed in nginx but I also have laravel sites with a simular setup who don’t have any problem so it’s a combined kirby/forge problem, not sure.

I’m using forge on linode (nginx + php-fpm) There wouldn’t be anybody with a simular problem wo would have an idea?

Cheers,
Sam

If I do an echo of Server::get(‘HTTP_HOST’) it comes out correctly, so it has to be deeper into Kirby that something goes wrong :thinking:

What is your Kirby version and is language detection enabled or not?

3.4, language detection is disabled. Here’s a screen from some debugging.
Still in doubt if I’m being an idiot and missing something easy or there’s really something funky going on here :grimacing:

Could you please post your config file or files (if you are using multiple) and your language files?

Sure mate. (and tx for taking the time to take a look)

config.php

<?php

return [
    'debug' => true,

    'languages' => true,

    'urls' => [
        'nl' => 'http://mijngeldenik.int',
        'fr' => 'http://financesetmoi.int',
    ],

    'placeholders' => [
        'year' => date('Y'),
    ],

    'panel.install' => true,

    'omz13.xmlsitemap' => [
        'cacheTTL' => 60,
        'includeUnlistedWhenSlugIs' => [],
        'includeUnlistedWhenTemplateIs' => ['blog', 'blog-post'],
        'excludePageWhenTemplateIs' => ['block-centered-content', 'block-comp-content', 'block-hero', 'block-table'],
        'excludePageWhenSlugIs' => [],
        'excludeChildrenWhenTemplateIs' => ['block-centered-content', 'block-comp-content', 'block-hero', 'block-table'],
        'disableImages' => false,
    ],

    'block' => [

        'background' => [
            'default' => '',
            'primary' => 'bgc--primary-1',
            'secondary' => 'bgc--secondary-1',
        ],

        'position' => [
            'normal' => '',
            'alt' => 'type-alt',
        ],

        'navigato-navigate' => [
            'class' => 'trigger--navigato-navigate',
        ],
        
    ],

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

    'bnomei.robots-txt.content' => null,
    'bnomei.robots-txt.sitemap' => null,
    'bnomei.robots-txt.groups' => [
        '*' => [
            'disallow' => [
                '/kirby/',
                '/site/',
            ],
            'allow' => [
                '/media/',
            ]
        ]
    ]
];

config.mijngeldenik.xxxx.be.php

<?php

return [

    'debug' => false,

    'urls' => [
        'nl' => 'https://mijngeldenik.xxxx.be',
        'fr' => 'https://financesetmoi.xxxx.be',
    ],
];

config.financesetmoi.xxxx.be.php

<?php

return [

    'debug' => false,

    'urls' => [
        'nl' => 'https://mijngeldenik.xxxx.be',
        'fr' => 'https://financesetmoi.xxxx.be',
    ],

];

nl.php

<?php

return [
    'code' => 'nl',
    'default' => true,
    'direction' => 'ltr',
    'locale' => [
        'LC_ALL' => 'nl_BE'
    ],
    'name' => 'Nederlands',
    'translations' => [
        'header.back_to_home' => 'Terug naar de homepagina',
        'header.mobile.back_to_home' => 'Homepage',
    ],
    
    'url' => option('urls.nl'),
];

fr.php

<?php

return [
    'code' => 'fr',
    'default' => false,
    'direction' => 'ltr',
    'locale' => [
        'LC_ALL' => 'fr_FR'
    ],
    'name' => 'Français',
    'translations' => [
        'header.back_to_home' => 'Retour à l\'accueil',
        'header.mobile.back_to_home' => 'Homepage',
    ],
    
    'url' => option('urls.fr'),
];

Hm, that looks all good to me.

Is this a new issue with 3.4 that you did not encounter with the previous version?

Quite puzzled myself also… This is the first time I use this ‘feature’. I’ve only worked with /nl /fr etc… in previous versions. Weird thing is that it does work on my localhost (the .int domains) so I honestly have no clue what the problem could be since the Server::get('http_host') comes through correctly.

I already have found a temporary solution. As suspected the problem is a combination of Kirby and nginx.

If I create a seperate vhost for the other language instead of an alias then it works … Not sure why this is though. (other (as in laravel,…) sites don’t have this problem)

This was the configuration before the temporary solution. (with both domains as a server_name)

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name mijngeldenik.xxxx.be financesetmoi.xxxx.be;
    server_tokens off;
    root /home/forge/mijngeldenik.xxxx.be/;

    ssl_certificate /etc/nginx/ssl/mijngeldenik.xxxx.be/847563/server.crt;
    ssl_certificate_key /etc/nginx/ssl/mijngeldenik.xxxx.be/847563/server.key;

    ssl_protocols TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/mijngeldenik.xxxx.be-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

This is the configuration after the temporary solution (seperate host per domain)

# FORGE CONFIG (DO NOT REMOVE!)
include forge-conf/mijngeldenik.xxxx.be/before/*;

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name mijngeldenik.xxxx.be;
    server_tokens off;
    root /home/forge/mijngeldenik.xxxx.be/;

    ssl_protocols TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    # FORGE CONFIG (DO NOT REMOVE!)
    include forge-conf/mijngeldenik.xxxx.be/server/*;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/mijngeldenik.xxxx.be-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name financesetmoi.xxxx.be;
    server_tokens off;
    root /home/forge/mijngeldenik.xxxx.be/;

    ssl_protocols TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/mijngeldenik.xxxx.be-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

#forge #nginx #kirby-3 #linode #ubuntu

That would have been my next question…

1 Like