We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • I've been setting up a multisite with several contexts and domains. Somehow it's not working. The main context/domainname is working fine, but the others are being redirected to www.firstdomain.nl.

    Here's my context settings for the 'second' context:
    base_url /
    http_host www.seconddomain.nl
    site_url https://www.seconddomain.nl/

    seconddomain.nl is set up as an alias of firstdomain.nl.

    Do I need some configuration in my htaccess? I think it should work this way.

    This question has been answered by handjes. See the first response.

    [ed. note: handjes last edited this post 5 years, 6 months ago.]
      • 46886
      • 1,154 Posts
      I think yes, htaccess is what you need. Presumably those redirects are causing you to go to maindomain.

      But, I am searching and finding nothing. Is the re-routing to subdomains not handled by htaccess?

      I am searching and getting nowhere. Let's figure out routing of those subdomains
        • 54641
        • 10 Posts
          MODx Version: 2.6.5-pl
          Developing in Local Page with:
          > MAMP 5.0
          > PHP 7.2.7
        • Ok. Some say it's not the htaccess file, some do.

          That link does not give me any information unfortunately.
            • 54653
            • 10 Posts
            Gerben,

            did you set up the index.php in each context to activate the right context?

            The last lines in each index.php should look like this (look for the line saying "/* Initialize the default 'web' context */"):

             
            /* Initialize the default 'web' context */
            // Comment the default web context initialization:
            //$modx->initialize('web');
            
            /* setup for multiple domains */
            switch(strtolower(MODX_HTTP_HOST)) {
                                                                                                       
            /* setup for multiple domains */
            
            switch(strtolower(MODX_HTTP_HOST)) {
               case 'www.firstdomain.nl :80':
               case 'www.firstdomain.nl :443':
               case 'www.firstdomain.nl':
                  // if the http_host is www.firstdomain.nl, load the second domain web context
                  $modx->initialize('first domain context');
                  break;
               case 'www.seconddomain.nl :80':
               case 'www.seconddomain.nl :443':
               case 'www.seconddomain.nl':
                  // if the http_host is www.seconddomain.nl, load the second domain web context
                  $modx->initialize('second domain context');
                  break;
               default:
                  // by default / if no other rule can be applied, load web context
                  $modx->initialize('web');
                  break;
            }
            
            /* execute the request handler */
            if (!MODX_API_MODE) {
                $modx->handleRequest();
            } 
            


            Also, make sure you have a site_start and an error_page defined for each context.

            Hope this helps,

            Massimo
            • Ok, thanks. There's a duplicate line in that code:

              /* setup for multiple domains */
              switch(strtolower(MODX_HTTP_HOST)) {

              But it's still not working. Everything is still being redirected to the web context. I did set up site_start and error_page.

              BTW: What do you mean with index.php for each context?


              [ed. note: handjes last edited this post 5 years, 6 months ago.]
              • This is what I have in my contexts:

                  • 54653
                  • 10 Posts
                  Gerben,

                  Your context configuration for cater.nl seems fine to me.
                  I guess your other context definition has http_host and site_url set for the other domain.
                  I would check the virtual host definitions in the web server and make sure that each definition contains the right ServerName/ServerAlias, DocumentRoot (or Alias) pointing to the exact disk location where each domain's assets and index.php are located.

                  This is pretty much what we have (I just used your cater.nl example):

                  
                  <VirtualHost *:443>
                      ServerName cater.nl
                      ServerAlias www.cater.nl
                  #
                    
                      # Disable aliases from system config
                      Alias / <path to cater's context directory>
                  
                      # debug, info, notice, warn, error, crit, alert, emerg
                      LogLevel warn
                      ErrorLog logs/cater-ssl_error_log
                      CustomLog logs/cater-ssl_access_log combined
                      ServerSignature On
                      ServerAdmin [email protected]
                      #
                      # SSL config without comments
                      #
                  
                      SSLEngine on
                      SSLCertificateFile /etc/pki/tls/certs/cater.crt
                      SSLCertificateKeyFile /etc/pki/tls/private/cater.key
                      SSLCertificateChainFile /etc/pki/tls/certs/InCommon-chain.crt
                  
                      #
                      # INTERMEDIATE configuration,
                      #    from:   https://wiki.mozilla.org/Security/Server_Side_TLS
                      #
                      #  IE6 and Java6 clients may have trouble
                      #
                      SSLProtocol             all -SSLv2 -SSLv3
                      SSLCipherSuite          ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA
                      SSLHonorCipherOrder     on
                      #SSLCompression          off
                  
                  
                      <Files ~ "\.(cgi|shtml|phtml|pcgi|php|php3?)$">
                          SSLOptions +StdEnvVars
                      </Files>
                      <Directory "/home/web/cgi-bin">
                          SSLOptions +StdEnvVars
                      </Directory>
                  
                  
                      SetEnvIf User-Agent ".*MSIE.*" \
                               nokeepalive ssl-unclean-shutdown \
                               downgrade-1.0 force-response-1.0
                  
                      # not sure I we want this - ASM 2013
                      #   Per-Server Logging:
                      #   The home of a custom SSL log file. Use this when you want a
                      #   compact non-error SSL logfile on a virtual host basis.
                      #CustomLog logs/ssl_request_log \
                      #          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
                  
                      #
                      # END of SSL config
                      #
                  
                  
                  
                  </VirtualHost>
                  


                  Note: We have a similar virtual host definition for port 80 for each domain, to make sure our server responds to http and https requests for all domains.


                  Hope it helps,

                  Massimo
                  • I have been working on it, trying the above. My provider is helping me with stuff like Virtual Host (which they do a great job at).

                    Also tried ContextRouter instead of XRouting; the interesting thing is: I am able to see the separate websites/domains when I am viewing pages from WITHIN MODX (the View option). The sites look fine. But accessing the alias domain names via the address bar is still not possible.
                      • 3749
                      • 24,544 Posts
                      Make sure you have a base href tag in all templates that's called uncached (with the exclamation point):

                      <base href="[[!++site_url]]" />


                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting