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

    I want to run two domains with one MODX Revo install - with the different URLs going to different contexts.

    I tried following these instructions, but they don't seem to work for me:
    http://www.belafontecode.com/modx-revolution-hosting-multiple-domains/

    I tried another variation which I found on these forums (can't find it now) where I think $modx->switchContext('Domain2'); was changed to $modx->initialize but no joy.

    My new context is set up properly - if I change the default to the new context name, I see the new site. But it's not doing the 'detecting' bit, I guess.

    Thanks for any help
      • 30912
      • 463 Posts
      Are you sure you've done the following:

      Routing Domain to Specific Folder on the Server

      Similar to our earlier approach, we’ll be using .htaccess directives to tell the server what the root folder should be for each domain. Last time, we set it so that it would automatically map to a folder based on the subdomain that was used to access the site. This time around, we won’t use that approach because we can’t guarantee that some things won’t get confusing on the server once all domain names are in place. That said, we’ll want to type the directives manually so that we have ultimate control over what folder names go with each domain.

      Open your ROOT FOLDER’S .htaccess file and paste the following:

      #MAP TLD TO CUSTOM SUBDIRECTORY
      RewriteCond $1 !^foldername/
      RewriteCond %{HTTP_HOST} ^www\.modxdomain2\.com
      RewriteRule (.*) /foldername/$1 [L]


      Ive used that site many times and have thus far never encountered an error, you need to ensure your domain mapping is correct for the context

      I would check all of your HTAcess and Modx Initiliase settings again, as thats usually where i fail

      HTH
        • 39079
        • 13 Posts
        Hello,

        I was trying option 1 on that page - so didn't go near htaccess.

        I don't know what I coudl be doing wrong, becuase the code is very simple. I just switched out the two domain references and changed the context name. But nada - the domains just drop me on my normal website context.

        Thanks.
          • 30912
          • 463 Posts
          Ah, i've never tried that appraoch, Ive always done it the htaccess route as its always worked for me.

          I'll try and find some time on an install to test option 1 and see if i can get it to work.
            • 39079
            • 13 Posts
            Thanks.

            Actually I just found this:
            http://modx.com/extras/package/gatewaymanager

            And that works a treat... so for me, issue over. smiley

            Thanks again.
              • 38159
              • 11 Posts
              I was using GatewayManager for subdomains, too, that works like a charm and helps a lot!

              But I was wondering how to use it with domains, i.e. how to assign a context to an external domain. Which entry in my zone file of the external domain would have to be changed, and how?

              Would I have to set a new CNAME 'www', point it to the domain name where MODx is installed, and use a .htaccess file like this so that all traffic is directed to the MODx install:

              RewriteEngine on
              RewriteCond %{HTTP_HOST} !^www. [NC]
              RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]

              Thanks for any help, Alex [ed. note: gugelhuhn last edited this post 13 years, 9 months ago.]
                • 38159
                • 11 Posts
                Great, got it to run now!

                As Bert has explained, I didn't have to fiddle with the zone file, but make the "external" domain an alias domain. So domain aliasing does the trick.

                Thanks again, Bert!
                  • 38159
                  • 11 Posts
                  Great, got it to run now!

                  As Bert Oost has explained, I didn't have to fiddle with the zone file, but make the "external" domain an alias domain. So domain aliasing does the trick.

                  Thanks again, Bert!