We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1611
    • 591 Posts
    Actually, I’ve got a 404 error while trying to do the same thing you described.
      • 16610
      • 634 Posts
      @worchyld: I have a couple subdomains configured this way and I haven’t encountered the problem you described. Maybe you can learn something useful from this that may help with your problem:

      # === www.test.example.com ===
      # First be sure to rewrite the request to a unique domain
      RewriteCond %{HTTP_HOST} .
      RewriteCond %{HTTP_HOST} !^test\.example\.com [NC]
      RewriteCond %{HTTP_HOST} ^www\.test\.example\.com [NC]
      RewriteRule (.*) http://test.example.com/$1 [R=301,L]
      
      # Rewrite the homepage of each domain to index.html
      RewriteRule ^$ /index.html
      
      # Do the other magic: Rewrite the the requests to for MODx readable folders
      RewriteCond %{HTTP_HOST} test\.example\.com [NC]
      RewriteCond %{REQUEST_URI} !^/manager
      RewriteCond %{REQUEST_FILENAME} index\.php [OR]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(index\.(html?|php)|test/)?(.*)$ index.php?q=/test/$3 [L,QSA]
      
        Mikko Lammi, Owner at Maagit
        • 30107
        • 44 Posts
        Quote from: Lammikko at Feb 04, 2010, 04:43 AM

        @worchyld: I have a couple subdomains configured this way and I haven’t encountered the problem you described. Maybe you can learn something useful from this that may help with your problem:

        # === www.test.example.com ===
        # First be sure to rewrite the request to a unique domain
        RewriteCond %{HTTP_HOST} .
        RewriteCond %{HTTP_HOST} !^test\.example\.com [NC]
        RewriteCond %{HTTP_HOST} ^www\.test\.example\.com [NC]
        RewriteRule (.*) http://test.example.com/$1 [R=301,L]
        
        # Rewrite the homepage of each domain to index.html
        RewriteRule ^$ /index.html
        
        # Do the other magic: Rewrite the the requests to for MODx readable folders
        RewriteCond %{HTTP_HOST} test\.example\.com [NC]
        RewriteCond %{REQUEST_URI} !^/manager
        RewriteCond %{REQUEST_comLENAME} index\.php [OR]
        RewriteCond %{REQUEST_comLENAME} !-f
        RewriteCond %{REQUEST_comLENAME} !-d
        RewriteRule ^(index\.(html?|php)|test/)?(.*)$ index.php?q=/test/$3 [L,QSA]
        


        Lammikko, may I ask you to provide me with the complete .htaccess file you’re using? I just can’t get around the problem I have described a few posts earlier: when I’m using QuickManager in conjunction with the multidomain feature (using the button "Edit Resource"), the system jumps (after saving of the edited page in QM) to the homepage instead of the page I’m editing. It makes multidomain unusable for me :-( It must have something to do with mod_rewrite, because it seems to work for everyone else.
          • 16610
          • 634 Posts
          Quote from: titanium at Feb 04, 2010, 06:53 AM

          Lammikko, may I ask you to provide me with the complete .htaccess file you’re using? I just can’t get around the problem I have described a few posts earlier: when I’m using QuickManager in conjunction with the multidomain feature (using the button "Edit Resource"), the system jumps (after saving of the edited page in QM) to the homepage instead of the page I’m editing. It makes multidomain unusable for me :-( It must have something to do with mod_rewrite, because it seems to work for everyone else.

          Actually I don’t use QM+ with my multiple domains configuration. But as an author of QM+ I’ll bet you will have problems with it. Unfortunately QM+ has never been tested with multiple domains as this is more like an advanced hack than a standard MODx feature.

          I think your problems are related to that when QM+ saves a document it tries to load the page like "www.example.com/index.php?id=5" instead of "www.example.com/your-site/page-5". Multiple domains hack needs friendly aliases to work so that’s probably why it’s breaking (jumps to start page).

          There’s not an easy fix for this because QM+ needs the "index.php?id=5" when saving if page alias has been changed and old alias path is not usable anymore.
            Mikko Lammi, Owner at Maagit
            • 32645
            • 377 Posts
            I will review your code and see if I can get it to work.

            Thanks.
              • 32645
              • 377 Posts
              Sorry, I’ve tried your code but it’s still letting me go to:

              http://www.example2travel.co.uk/example2spain-co-uk/

              It shouldn’t be doing that.

              Do I need to be putting in a route for the top level domain "example2travel"? I tried that, but that doesn’t stop the problem.

              My setup is that:


              + [folder] www.example2spain.co.uk
              - somethinginhere.html

              + [folder] www.anothernichedomain.co.uk
              - somethinginhere.html

              All other stuff relating to example2travel goes here.


              Unfortuently it would be really difficult and very messy to create a folder specifically for example2travel, so this is why all requests to the top domain do not go to a folder.

              Maybe I’m doing something wrong? Has there been any updates to the code/htaccess? I’ve even gone to the trouble of going through the code of the tutorial to no avail.

              Thanks.


                • 30741
                • 65 Posts
                I am wondering - I have 7 domains setup now in this system, and it has been working well for the first 4 domains. But after that it does not work. Whatever order I put the domains in it stops working for domain # 5-7. Am I missing a config setting?
                If i change the order still the first 4 work, but none after that.

                I really appreciate this hack. It is a great addition to modx.
                  • 30741
                  • 65 Posts
                  Never mind - I was trying to do it too quick, and didn’t even pay attention that I put the other domains after these lines -
                  # The Friendly URLs part for the rest (or the main domain)
                  RewriteCond %{REQUEST_FILENAME} !-f
                  RewriteCond %{REQUEST_FILENAME} !-d
                  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

                  So all is well with the sites now.
                    • 32645
                    • 377 Posts
                    I’ve gone through the tutorial again and I think I must have typed something in wrong.

                    Anyway, I did a test on one of the niche domains we have and was able to stop users going to:


                    www.topleveldomain.co.uk/somenichedomain-co-uk/

                    The above now produces 404 errors! This is great as is what is to be expected.

                    However, users can still get to child items.

                    For example;


                    www.topleveldomain.co.uk/somenichedomain-co-uk/somechild/

                    Is still accessible.

                    Perhaps it just needs a trailing slash in the htaccess file, which i have posted below:

                    # Actual domain name altered for security
                    
                    # === START: domain stuff ===
                    
                    # First be sure to rewrite the request to a unique domain
                    RewriteCond %{HTTP_HOST} .
                    RewriteCond %{HTTP_HOST} ^travel2spain\.co.uk [NC]
                    RewriteCond %{HTTP_HOST} !^www\.travel2spain\.co.uk [NC]
                    RewriteRule (.*) http://www.travel2spain.co.uk/$1 [R=301,L]
                    
                    # rewrite the homepage of each domain to index.html
                    RewriteRule ^travel2spain-co-uk$ /index.html
                    
                    # do the other magic: Rewrite the the requests to for MODx readable folders
                    RewriteCond %{HTTP_HOST} travel2spain\.co.uk [NC]
                    RewriteCond %{REQUEST_URI} !^/manager
                    RewriteCond %{REQUEST_FILENAME} index\.php [OR]
                    RewriteCond %{REQUEST_FILENAME} !-f
                    RewriteCond %{REQUEST_FILENAME} !-d
                    RewriteRule ^(index\.(html?|php)|travel2spain-co-uk)?(.*)$ index.php?q=/travel2spain-co-uk/$3 [L,QSA]
                    
                    
                    # === END: domain stuff ===
                    
                    

                      • 32645
                      • 377 Posts
                      Hi,

                      I’ve gone through the tutorial again and double checked my code posted above against the one in the tutorial:

                      // This is from the tutorial
                      RewriteEngine On
                      RewriteBase /
                      # First be sure to rewrite the request to a unique domain
                      RewriteCond %{HTTP_HOST} .
                      RewriteCond %{HTTP_HOST} ^domain1\.com [NC]
                      RewriteCond %{HTTP_HOST} !^www\.domain1\.com [NC]
                      RewriteRule (.*) http://www.domain1.com/$1 [R=301,L]
                      # rewrite the homepage of each domain to index.html
                      RewriteRule ^domain1-com\.html$ /index.html
                      # do the other magic: Rewrite the the requests to for MODx readable folders
                      RewriteCond %{HTTP_HOST} domain1\.com [NC]
                      RewriteCond %{REQUEST_URI} !^/manager
                      RewriteCond %{REQUEST_FILENAME} index\.php [OR]
                      RewriteCond %{REQUEST_FILENAME} !-f
                      RewriteCond %{REQUEST_FILENAME} !-d
                      RewriteRule ^(index\.(html?|php)|domain1-com)?(.*)$ index.php?q=/domain1/$3 [L,QSA]
                      
                      



                      Although I’ve fixed the inital problem I reported (of people able to get to somedomain.com/somepageslug-co-uk/), users can still access child items.

                      Perhaps I’ve missed something, or someone can point out how to post their htaccess file so I can compare it with our own -- that way I can see if there are any major problems.

                      Thanks