We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22775
    • 15 Posts
    I need a solution for a combination of multidomain/multisite and multilingual. I need one MODX for one customer with two websites, that use different domains. Both are multilanguage sites.

    In detail it should look like this:

    domain1.tld/de/
    domain1.tld/en/
    domain2.tld/de/
    domain2.tld/en/
    domain2.tld/it/

    Babel can handle multisite, GatewayManager routes the domains. But I can't get it to work in combination. I also tried XRouting and ContextRouter.

    Any idea or experience?
    Thanks in advance

    This question has been answered by achterbahn. See the first response.

    • discuss.answer
      • 36818
      • 119 Posts
      Hi patstar,

      I managed it without GatewayManager and such.

      Just a gateway-plugin (system event: OnHandleRequest):
      <?php
      if($modx->context->get('key') != "mgr"){
      
      $host = $modx->getOption('http_host');
      $ck = $_REQUEST['cultureKey'];
      
      	switch ($host) {
      		case ($host == 'www.domain1.tld:80' && !$ck):
      		case ($host == 'www.domain1.tld' && !$ck ):
      			// if the http_host is of a specific domain, switch the context
      			$modx->switchContext('context1');
      		break;
      
      		case ($host == 'www.domain1.tld:80' && $ck == 'en'):
      		case ($host == 'www.domain1.tld' && $ck == 'en'):
      			// if the http_host is of a specific domain, switch the context
      			$modx->switchContext('context2');
      		break;
      	
      		case ($host == 'www.domain2.tld:80' && $ck == 'de'):
      		case ($host == 'www.domain2.tld' && $ck == 'de'):
      			// if the http_host is of a specific domain, switch the context
      			$modx->switchContext('web');
      		break;
      	
      		case ($host == 'www.domain2.tld:80' && $ck == 'en'):
      		case ($host == 'www.domain2.tld' && $ck == 'en'):
      			// if the http_host is of a specific domain, switch the context
      			$modx->switchContext('context3');
      		break;
      	
      		default:
      			// fallback, go to main context
      			$modx->initialize('web');
      		break;
      	}
          /* unset GET var to


      and the htaccess modifications for babel:
          # Special for Babel Multilanguage Site (MODX Extra)
          # redirect all requests to /de/favicon.ico and /nl/favicon.ico
          # to /favicon.ico
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule ^(de|en)/favicon.ico$ modx/favicon.ico [L,QSA]
             
          # redirect all requests to /de/assets* and /nl/assets* to /assets*
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule ^(de|en)/assets(.*)$ assets$2 [L,QSA]
      
          # redirect all other requests to /de/* and /nl/*
          # to index.php and set the cultureKey parameter
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule ^(de|en)?/?(.*)$ index.php?cultureKey=$1&q=$2 [L,QSA]
        • 22775
        • 15 Posts
        Hi achterbahn

        Thanks a lot for you solution. I have to give it a try the next time.
        For this time I had to go on quickly and had to solve it with subdomains like de.domain1.tld instead of domain1.tld/de (this works easy with Babel and GatewayManager).
        I'm sure, the next project with similar requirements will come soon.