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

    I’ve been in the seventh circle of hell for the last few days trying to get a VPS configured and domains set up for a new project I’m working on, but I think I’ve finally got it. However, I have tried everything I can think of to get one of the two tutorials I’ve seen working for using multiple top-level domains with one MODx Revo intall:

    RTFM version: http://rtfm.modx.com/display/revolution20/Using+One+Gateway+Plugin+to+Manage+Multiple+Domains
    Belafontecode version: http://www.belafontecode.com/modx-revolution-hosting-multiple-domains/

    Can someone please help? I’m desperate and have tried everything I could find in the forums with little success. Here’s my setup:

    1. My hosting is a Smart VPS with Liquid Web.
    2. My domains are registrared with GoDaddy. I’m also using GoDaddy’s nameservers, and have just set the A records to point to the IP of the Liquid Web server.
    3. I have nothing else installed on the site yet.
    4. There are two contexts: "web" and "florida" (eventually there will be a context for every state).

    Both domains are displaying the index of the "web" context perfectly. However, no matter which method I use above, MODx never seems to recognize a different http_host (I’m speculating here, but that’s what it seems like) and make the switch to "florida." Has anyone had this experience? Suggestions on what I’m doing wrong here?
    • - What context settings are you using?
      - Are you getting any errors in the error log?>
      - What does your plugin look like?

      I personally always use this method: http://rtfm.modx.com/display/revolution20/Creating+a+Subdomain+from+a+Folder+using+Virtual+Hosts (skipping the part of creating a virtual host) and never had any issues with that.
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
      • I don’t see any problem giving my real domains here, so, my primary domain is pancakeinc.com, and my new context is floridapancake.com. We’ll be adding a new domain for each state over time (i.e., kansaspancake.com, texaspancake.com, etc.).

        1. My context settings (context name is "florida") look like this:

        base_url: /
        http_host: floridapancake.com
        site_start: 2 (this is the only page in my "florida" context, and it's published)
        site_url: http://www.floridapancake.com



        2. I’ve got two entries in my error log that look like this:

        [2011-07-13 22:43:27] (ERROR @ /connectors/context/index.php) modManagerLog: Attempt to set NOT NULL field item to NULL
        [2011-07-13 22:54:18] (ERROR @ /connectors/element/plugin.php) modPluginEvent: Attempt to set NOT NULL field priority to NULL


        3. I’ve tried both methods above. Using the RTFM method, my plugin looks like this:

        <?php
        /* don't execute if in the Manager */
        if ($modx->context->get('key') == 'mgr') {
            return;
        }
         
        switch ($modx->getOption('http_host')) {
           case 'floridapancake.tld:80':
           case 'floridapancake.tld':
              // if the http_host is of a specific domain, switch the context
              $modx->switchContext('florida');
              break;
           default:
              // by default, don't do anything
              break;
        }


        Using the Belafonte method, my modified index.php code looks like this:

        /* Setup context mapping */
        switch ($modx->getOption('http_host')) {
        	case 'floridapancake.com:80':
        	case 'floridapancake.com':
        		// if the http_host is of a specific domain, switch the context
        		$modx->switchContext('florida');
        	break;
        
        	default:
        		// fallback, go to main context
        		$modx->initialize('web');
        	break;
        }


        Does any of this help? Those errors seems important to this, but I’m not sure what they mean. Thanks for the suggestion on the virtual hosts method. I could try that, but I’m actually wanting multiple top-level domains here...would that work for this?
          • 28743
          • 10 Posts
          I had a similar problem recently.

          This worked for me - not sure how "correct" it is but got me out of a hole:

          /* Setup context mapping */
          switch ($_SERVER['HTTP_HOST']) {
          	case 'm.domainname.co.uk:80':
          	case 'm.domainname.co.uk':
          		// if the http_host is of a specific domain, switch the context
          		$modx->initialize('mobile');
          	break;
          
          	default:
          		// fallback, go to main context
          		$modx->initialize('web');
          	break;
          }
          • Success!!! Thanks, @studiorepublic -- that worked great. I won’t even admit how much time I could’ve saved by asking the community from the beginning. Can’t thank you enough.

            Just curious...does anyone smarter than me know why the original method doesn’t work? Or see any concerns with doing it this way?
              • 28743
              • 10 Posts
              Yep - that was about two hours worth of head scratching and trial and error!
              • Two hours? I wish! wink Between that issue, DNS issues at GoDaddy and permissions issues that forced me to recompile Apache to use suPHP instead of DSO, I was ready to scrap this whole web-developer career and learn to drive an ice cream truck or something.
                  • 15566
                  • 73 Posts
                  I know you’ve resolved this, but here’s some useful instructions:

                  http://www.unchi.co.uk/2011/05/04/create-multiple-websites-using-one-installation-of-modx-revolution/
                    • 577
                    • 132 Posts
                    This is outside of MODX but what I do and it takes all the headaches away.

                    Assuming you have full access on the server or at least enough access in .htaccess here is a solution

                    In the apache config file of .htaccess file for your site
                    SetEnv SITE_CONTEXT ethannewmedia
                    


                    Then in your MODX index.php root file

                    OLD:
                    /* Initialize the default 'web' context */
                    $modx->initialize('web');
                    


                    NEW:
                    /* Initialize the default 'web' context */
                    $modx->initialize(getenv('SITE_CONTEXT'));
                    


                    And your done.

                    You can also do this with the CONTEXT_KEY if you have various configs setup (under advanced install) inside of one copy of MODX.

                      "One of these days I will get around to my own website... Its only been about 12 years... maybe tomorrow smiley"
                    • Thanks for the suggestions, everyone. i ended up sticking with the modified @studiorepubic versions, but it’s good to see some of these other methods in case I (or others) need them down the road. So, is the documentation for the two methods I initially listed incorrect then? Or is it just a server-by-server case where things (like not being able to grab http_host via MODx API) don’t work?