We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36575
    • 104 Posts
    Hi,

    I have a site running 2.1.3 that I am trying to set up contexts on. I'm following this tutorial:
    http://www.belafontecode.com/modx-revolution-hosting-multiple-domains/#option2

    I have this working successfully on two other sites that I have, however, they are not using 2.1.3 (one is 2.0.8 and the other 2.1.2).

    Have there been any other changes in versions that might affect how things work?

    I thing it is specifically this code in the index.php file:

    /* setup for multiple domains */
    switch(strtolower(MODX_HTTP_HOST)) {
       case 'http://www.nanettecameron.net/:80':
       case 'http://www.nanettecameron.net/':
          // if the http_host is http://www.nanettecameron.net/, switch the context to web
          $modx->initialize('web');
          break;
       case 'www.inpursuitofvenus.com:80':
       case 'www.inpursuitofvenus.com':
          // if the http_host is inpursuitofvenus.com, switch the context to inpursuitofvenus.com
          $modx->initialize('venus');
          break;
       
      default:
          // by default / if no other rule can be applied, load 'web' context
          $modx->initialize('web');
          break;
    }


    Both sites currently go to the web context, but if i just use this line: $modx->initialize('web'); and change it to $modx->initialize('venus');
    then I am able to get to the venus context.

    Any ideas?


    • The code you have posted is not even valid PHP syntax. Regardless, you need to remove whatever the case statements are looking for anchor tags in the MODX_HTTP_HOST. This will never contain anything other than the host name and optionally the port number requested by the client browser.
        • 36575
        • 104 Posts
        thanks... for some reason the code has come out completely different to how I had it! I'll try copying it again


        /* setup for multiple domains */
        switch(strtolower(MODX_HTTP_HOST)) {
           case 'www.nanettecameron.net:80':
           case 'www.nanettecameron.net':
              // if the http_host is http://www.nanettecameron.net/, switch the context to web
              $modx->initialize('web');
              break;
           case 'www.inpursuitofvenus.com:80':
           case 'www.inpursuitofvenus.com':
              // if the http_host is inpursuitofvenus.com, switch the context to inpursuitofvenus.com
              $modx->initialize('venus');
              break;
           
          default:
              // by default / if no other rule can be applied, load 'web' context
              $modx->initialize('web');
              break;
        }
          • 36575
          • 104 Posts
          nope, try again...

          /* setup for multiple domains */
          switch(strtolower(MODX_HTTP_HOST)) {
             case 'www.nanettecameron.net:80':
             case 'www.nanettecameron.net':
                // if the http_host is www.nanettecameron.net, switch the context to web
                $modx->initialize('web');
                break;
             case 'www.inpursuitofvenus.com:80':
             case 'www.inpursuitofvenus.com':
                // if the http_host is inpursuitofvenus.com, switch the context to inpursuitofvenus.com
                $modx->initialize('venus');
                break;
             
            default:
                // by default / if no other rule can be applied, load 'web' context
                $modx->initialize('web');
                break;
          }
            • 36575
            • 104 Posts
            It's the venus context that I can't get to load. It just automatically redirects to the main site (www.nanettecameron.net) every time I try it. The only way I can see this context is if I change this:

            $modx->initialize('web');


            to this

            $modx->initialize('venus');
              • 36575
              • 104 Posts
              i've tried the case 'www.nanettecameron.net:80': with and without the www. Neither makes a difference.
              • And without the 80, correct? 80 will almost never appear in the http_host value since it is the standard port for web requests.
                  • 36575
                  • 104 Posts
                  yes, have tried both. Have also tried the gateway plugin, and no joy with that either. I think i'll try upgrading to 2.1.5

                    • 4955
                    • 32 Posts
                    for those who are struggleing with the routing of their content. the second domain pulls content from the 1st for / try this:

                    context->get('key') != "mgr"){
                    /* grab the current langauge from the cultureKey request var */
                    switch ($_REQUEST['cultureKey']) {
                    case 'de':
                    /* switch the context */
                    if ('www.1.eu' == $_SERVER['SERVER_NAME'])
                    {
                    $modx->switchContext('web');
                    }
                    elseif ('www.2.eu' == $_SERVER['SERVER_NAME'])
                    {
                    $modx->switchContext('2-de');
                    }
                    break;
                    case 'en':
                    /* switch the context */
                    if ('www.1.eu' == $_SERVER['SERVER_NAME'])
                    {
                    $modx->switchContext('1-en');
                    }
                    elseif ('www.2.eu' == $_SERVER['SERVER_NAME'])
                    {
                    $modx->switchContext('2-en');
                    }
                    break;
                    default:
                    /* Set the default context here */
                    /*set nothing here!!!*/
                    break;
                    }
                    /* unset GET var to avoid
                    * appending cultureKey=xy to URLs by other components */
                    unset($_GET['cultureKey']);
                    }

                    this worked for me in the end. multi domain incl. multi language set up
                    c--
                    • I would very much like to know how you deal with multiple domains, each domain with multiple languages. For example, domain1.com/en/ and domain2.com/en/
                        Studying MODX in the desert - http://sottwell.com
                        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                        Join the Slack Community - http://modx.org