We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 813 ☆ A M B ☆
    • 326 Posts
    I'm looking for a little advice here more than anything. Basically, I've got a multi-context MODx install, and each context is mapped back to its own unique URL (using a little switch statement hack in the index.php file). In other words, domain1.com is "web" context, domain2.com is "domain2" context, etc.

    My plan is to use the "web" context as sort of a data repository, and at least at this point, it doesn't have an actual front-facing site attached to it (it might in the future, but that's not important for this conversation).

    However, I'd like the ability to link a URL alias on these other contexts back to a related resource on "web" (i.e., if you visit domain2.com/about, it will actually pull the rendered page from domain1.com/about, which is in "web"), without changing the URL.

    I've thought of a few ways to do this, including a method I've used before, which is to write a plugin that fires on OnPageNotFound and redirects to a sort of "routing" page (i.e., domain2.com?page=about). This would work, but I'd ideally like to keep my URL from changing, and just grab the content in-place. Symlinks are out, because I need to grab a lot of stuff (TVs, etc.) from the "web" resource, and not just content.

    Any suggestions here? I've seen some similar posts on the forums, but so far, no perfect solutions. Thanks!
    [ed. note: aladage last edited this post 14 years, 7 months ago.]
      • 33988
      • 110 Posts
      Well if you wanted to make the setup you are talking about work you could create a TV for all of the documents not in the web context. The TV would hold the document ID of the document in the web context to pull the information from. Then you would need a plugin that would probably fire OnWebPagePrerender (not 100% sure). The plugin would grab the content from the documnet specified in the TV and overwrite the data in the current document before it is output.

      If I were to do another way, I would only use one context for the whole setup and direct all of your domains to that context (you can setup Apache to not change the URL input, making the user think they are on the site intended). Then I would write a snippet to detect which site is being accessed and manipulate the template so that the site displayed is the correct theme, etc. This assumes that all of your sites are identical in content and simply need to be restyled. However, if they are not identical in content you could make a checkbox TV to mark which sites are allowed to view a certain page and then have a plugin trigger a 404 if viewing is not allowed for that domain. This method may be a little harder or easier, but more sustainable in the end.

      I haven't really tried either of these, both or neither may work in the end. I suspect both would however.

      On a side note, you should remove your index hack and make a plugin like this http://rtfm.modx.com/display/revolution20/Using+One+Gateway+Plugin+to+Manage+Multiple+Domains.

      Let us know how it goes.
        Sal Sodano
        President & Co-Founder of SkyToaster
        My Website Salscode.
        • 12066
        • 48 Posts
        Hi @aladage,

        I was dealing with some related stuff and come up with this. I have absolutely no clue if this is the way to do it or if it's actually buggy on some other spot. But for me it works.

        Some notes on the code below:
        I needed to change the content disposition based on a GET-Parameter to make static resources ( with content_dispo = 1 ) available for Fancybox. But it should work as well with the other object properties.

        System Events to hook into: 'OnWebPageInit' and 'OnWebPageComplete'

        <?php
        /**
         * changeDisposition
         * Temporarily changes the content disposition of a MODX resource
         *
         * Fires first when a new page ('resource') is initialised and changes the content to inline
         * When page completes, this should be changed back again
         *
         */
        
        if(!$_GET['c'] && $_GET['c'] != 1)
            return false;
        
        if(!$modx->context->get('key') == 'context')
          return false;
        
        $eventName = $modx->event->name;
        $modx->event->output($eventName);
        switch($eventName) {
            case 'OnWebPageInit':
                $id = $modx->resourceIdentifier;
                $res = $modx->getObject('modResource', array('id' => $id));
                if($res->get('content_dispo') == 1)
                    $res->set('content_dispo', 0);
                $res->save();
                break;
            
            case 'OnWebPageComplete':
                $id = $modx->resourceIdentifier;
                $res = $modx->getObject('modResource', array('id' => $id));
                if($res->get('content_dispo') == 0)
                    $res->set('content_dispo', 1);
                $res->save();
                break;
        }
        
        return;


        What do you think?
          • 813 ☆ A M B ☆
          • 326 Posts
          @herooutoftime Sorry for the slow response; I somehow missed your message. This looks great! I'll give it a try soon and let you know if I have issues.