Back to Multi Domains Support

hei52749
hei52749

Hello, I have a one-page website in two different languages and bought two different domains. I would like each domain to activate a specific language. For example, I would like my-fr-domain.com to act as if I go on my-fr-domain.com/fr and my-nl-domain.com to my-nl-domain.com/nl so the Translate plugin knows the language. At the moment, when I go to my-nl-domain.com, it redirects to my-fr-domain.com without changing language. How should I create the domains binds?

Thank you for your help.

Linkonoid
Linkonoid

Hello! For this configuration to work properly, you must disable the language prefix substitution for the page ("Force URL schema" in localePicker component not checked, this not changes the structure of Url). Both domains must be with the option "ALL_THEME_PAGES_WITH_ROUTE_PATCH", and do not forget to include the "Hard Mode" in the plugin settings. I will try tomorrow to make an example on a test server for domains with different languages ​​with the Translate plugin enabled.

hei52749
hei52749

Hello, Thank you for your help.

  • Force URL schema was not checked;
  • I cannot find the option "ALL_THEME_PAGES_WITH_ROUTE_PATCH", where is it?
  • Hard mode is now activated; Here is how my domains are configured: https://imgur.com/a/uNX05Po
Linkonoid
Linkonoid

Hello!

Option "ALL_THEME_PAGES_WITH_ROUTE_PATCH" sets in Page dropdown (first element).

Live Demo for uses standard localePicker component on Page: https://en.mdomains.test.linkonoid.com/ https://de.mdomains.test.linkonoid.com/

and use this code in Code-Section of Page Layout:

function onInit()
{
    $host = Request::getHost();
    $translator = class_exists('\RainLab\Translate\Classes\Translator') ?  \RainLab\Translate\Classes\Translator::instance() : null;

    if (!is_null($translator) && !empty($host))
    switch ($host) {
    case 'de.mdomains.test.linkonoid.com':
        $translator->setLocale('de',true);
        break;
    case 'ru.mdomains.test.linkonoid.com':
        $translator->setLocale('ru',true);
        break;        
    default:
       $translator->setLocale('en',true);
    }

}

function onSwitchLocale()
{
    switch (input('locale')) {
    case 'de':
        return Redirect::to('https://de.mdomains.test.linkonoid.com');
    case 'ru':
        return Redirect::to('https://ru.mdomains.test.linkonoid.com');
    default:
        return Redirect::to('https://en.mdomains.test.linkonoid.com');        
    }
}

Perhaps I will someday add similar code to the plugin itself, but working with translation is a slightly different sfera, clearly not related to the of the Mdomains-plugin

Last updated

hei52749
hei52749

Hello, Thank you for your message. It unfortunately does not work. When I insert your code, I cannot even change language anymore and the "secondary" domain keeps redirecting to the main one. I think that the main issue is here, there is something in the website that forces the domain to be mydomain-fr.be and automatically redirects mydomain-nl.be to mydomain-fr.be. I checked the .htaccess and did not find any rule about this. Any idea?

Linkonoid
Linkonoid

Hi!

Perhaps you have a Redirect on server-level or in others of October plugins.

My test config is like this (mdomains / admin: https://mdomains.test.linkonoid.com/backend/backend/auth/signin):

  1. DNS for domains is registered through an A-record pointing to one IP (the main working domain is different from the languages ones):
    • mdomains.test.linkonoid.com - basic
    • en.mdomains.test.linkonoid.com - secondary
    • de.mdomains.test.linkonoid.com - secondary

I understand that you have only 2 domains and one of them is the base? Those. you need to create only one bind for the secondary domain. For the base domain, it’s better not to create binds (the default settings for it) or use a configuration similar to mine.

  1. Caddy's Web Server on which virtual hosts hang, indicating the only installation of October, i.e. to the entry point index.php (similarly in Nginx and Apache)
  2. The plugin settings are set to "Hard mode" (this is important, after its inclusion in the file modules/cms/classes/router.php there should be my comments, check, because sometimes it flies after Build-updates), only the option "ALL_THEME_PAGES_WITH_ROUTE_PATCH is set ", everything else is disabled.
  3. The above code is registered in the theme template (Page Layout for pages, there is sets only one theme for both domains)

Last updated

Linkonoid
Linkonoid

Plugin update to v1.4.0

Layout Code-section for support language domains of this structure: locale.domain.tld, locale - from avaiable locale in CMS ("en","de","ru"....)

function onSwitchLocale()
{
        return Redirect::to($this->page->redirectUrl); 
}

Last updated

1-7 of 7