Redirect issues in multi-language setup

Hello!

I’ve been using this method

to serve a page from my website for this domain

https://www.vortrag-digitalisierung.com

  • a keyword domain for some of my content.

After switching the site to multi language , however, some internal redirect causes the address bar to change to the ‘long URL’ you see now when going to the domain. How would I ideally avoid this?

I thought about doing a simple RewriteRule thing. Can I pass a slug - and language code - to Kirby’s index.php, so that it gets rendered with no redirects happening?

Thanks a lot!
Fabian

What is the expected behavior. Which language variant do you want to show under the domain above?

I’d like to show the page currently displayed - which is German-only - but without the address bar changing.

And what is your default language?

Could you please post your language configuration, your config.php and what exactly you put into your index.php?

I can only test this locally with Valet and works as expected even in a multi-lang setting. But looks like you are using different domains per language?

Hello! Thanks for taking care of this!

My default language is English.

My config.php:

<?php


return [

	'debug' => true,

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

	'omz13.xmlsitemap.cacheTTL' => 0,
	'omz13.xmlsitemap.disableImages' => true,
	'omz13.xmlsitemap.includeUnlistedWhenSlugIs' => ['home', 'talks', 'teaching', 'publications', 'contact', 'motivation', 'projects', 'press', 'projects'],
	'omz13.xmlsitemap.includeUnlistedWhenTemplateIs' => ['project', '', '', '' ],
	'omz13.xmlsitemap.excludePageWhenTemplateIs' => [ 'talk','publication','press_coverage' ],
	'omz13.xmlsitemap.excludePageWhenSlugIs' => [ 'form' ],
	'omz13.xmlsitemap.excludeChildrenWhenTemplateIs' => [ '' ],

];

Here is my complete index.php (covering several of those keyword domains):

    <?php

require __DIR__ . '/kirby/bootstrap.php';



function domaincheck($domain) {

    $url = rtrim(strtolower((new Kirby)->request()->url()),"/");

    if (
        ($url == "http://localhost/fabianhemmert.com/$domain") || 
        ($url == "http://$domain") || 
        ($url == "https://$domain") || 
        ($url == "http://www.$domain") || 
        ($url == "https://www.$domain") 

    ) {
        return true;
    } else {
        return false;
    }

}



if (domaincheck('experte-digitalisierung.de')) {
	c::set('customtitle',"Experte für Digitalisierung");
    echo (new Kirby)->render('keyword-domains/experte-digitalisierung-de');

} elseif (domaincheck('experte-innovation.de')) {
	c::set('customtitle',"Experte für Innovation");
    echo (new Kirby)->render('keyword-domains/experte-innovation-de');

} elseif (domaincheck('keynote-speaker-digitalisierung.de')) {
	c::set('customtitle',"Keynote Speaker zum Thema »Digitalisierung«");
    echo (new Kirby)->render('keyword-domains/keynote-speaker-digitalisierung-de');

} elseif (domaincheck('keynote-speaker-innovation.de')) {
	c::set('customtitle',"Keynote Speaker zum Thema »Innovation«");
    echo (new Kirby)->render('keyword-domains/keynote-speaker-innovation-de');

} elseif (domaincheck('redner-digitalisierung.net')) {
	c::set('customtitle',"Redner zum Thema »Digitalisierung«");
    echo (new Kirby)->render('keyword-domains/redner-digitalisierung-net');

} elseif (domaincheck('redner-innovation.org')) {
	c::set('customtitle',"Redner zum Thema »Innovation«");
    echo (new Kirby)->render('keyword-domains/redner-innovation-org');

} elseif (domaincheck('vortrag-innovation.com')) {
	c::set('customtitle',"Vortrag »Innovation«");
    echo (new Kirby)->render('keyword-domains/vortrag-innovation-com');

} elseif (domaincheck('vortrag-digitalisierung.com')) {
	c::set('customtitle',"Vortrag »Digitalisierung«");
    echo (new Kirby)->render('keyword-domains/vortrag-digitalisierung-com');

} elseif (domaincheck('vortrag-kreativitaet.de')) {
	c::set('customtitle',"Vortrag »Kreativität«");
    echo (new Kirby)->render('keyword-domains/vortrag-kreativitaet-de');
} else {
    echo (new Kirby)->render();
}

Here is my language config:

de.php:

<?php

return [
    'code' => 'de',
    'default' => false,
    'direction' => 'ltr',
    'locale' => [
        'de_DE'
    ],
    'name' => 'Deutsch',
    'url' => 'https://www.fabianhemmert.de',
];



en.php:

<?php

return [
  'code' => 'en',
  'default' => true,
  'direction' => 'ltr',
  'locale' => 'en_US',
  'name' => 'English',
   'url' => 'https://www.fabianhemmert.com'
];

// 'url' => 'https://example.com'

?>

The keyword domain subpages, like this one

https://www.fabianhemmert.com/keyword-domains/vortrag-digitalisierung-com

(which I want to serve directly under the keyword domains) are in German language only, but I duplicated them to exist also in English (hard-coding a “de” lang-code into the header for those pages).

Again, thanks for your help!

Hm, yes, it always redirects to the default language domain in this case. I found that even if you don’t use different domains, the language code and page slug are added as path to the single-page domain, so obviously, language redirects kick in later and I have no idea how to prevent that.

I just tested just returning the page and this seems to work:

if ($_SERVER['SERVER_NAME'] === 'notes.delete.test' && $_SERVER['REQUEST_URI'] === '/' ) {
    echo page('somepage')->render();
} else {
    echo (new Kirby)->render();
}
1 Like

I see! Can I pass a slug and language code to index.php? I might be able to hack it into .htaccess then.

Did you see my last post?

(I hadn’t seen your last post, sorry!)

The above solution – using the page – works great! Thanks!