We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34120
    • 236 Posts
    Hi all, I’m struggling to get context switching working, I’ve been working from the following links:
    http://rtfm.modx.com/display/revolution20/Using+One+Gateway+Plugin+to+Manage+Multiple+Domains
    http://www.belafontecode.com/modx-revolution-hosting-multiple-domains/

    It just doesn’t seem to have any effect, no errors, nothing.

    I’ve added this code to the root index.php file.
    switch ($modx->getOption('http_host')) {
    	case 'domain2.co.uk:80':
    	case 'domain2.co.uk':
    		// if the http_host is of a specific domain, switch the context
    		$modx->switchContext('domain2');
    	break;
    
    	default:
    		// fallback, go to main context
    		$modx->initialize('web');
    	break;
    }


    I’ve created my domain2 context and added all the settings: site_start, base_url, http_host and site_url. I’ve checked these details over and over. When I enter the 2nd domain it just functions as a parked domain and points to my primary domain. Also I can’t preview the resource I created in my new context.

    My second domain is parked rather than an addon domain, does this matter?
    Just noticed ’Virtual Directory Support’ is disabled, could that be anything?

    I’m out of ideas now, help much appreciated as always, Ta

    MODx Revolution 2.0.8-pl (traditional), Using FURLS, parked domain, PHP 5.2.14
      • 26016
      • 561 Posts
      Hi,
      It looks like you’re reading in the right place. And there is a way to do this by editing the index.php. But the block of code you’re showing there is for a different approach, via a plug-in. This method is totally different from the index.php method.

      I would suggest going to Elements, click New Plugin, and add your code there. I would also add

      <?php

      as the first line of the code (although it may add that for you automatically, I can’t remember)
      ... and then add
      return;
      as the last line of the code.

      Then click the System Events tab above. Then put a checkmark next to "OnHandleRequest" and save.

      That should help, unless something else isn’t set up right. You may need to remove that code from the index.php to get it all working.

      Hope that helps,
      Dave
        MODx and Wordpress development
        Linux, PHP 5.2, MySQL 5.0, Evo 1.05, Revo 2.08-pl, Firefox 4
        • 22303 MODX Staff
        • 10,725 Posts
        It all depends on how the domain is "parked". I suspect it is just redirecting traffic to the main domain and reporting the main domain as the $_SERVER[’HTTP_HOST’] value. Maybe...
          • 34120
          • 236 Posts
          Thanks for the replies, I’m not sure what was going on but I started over and followed the 2nd link and got it working.

          I got the context working properly then discovered that my Wayfinder calls were no longer working. In case anyone else is having this problem; Wayfinder now has context support so updating to the latest version should allow you to get things working https://github.com/splittingred/Wayfinder/issues/8