We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32963
    • 1,732 Posts
    Hell everyone,

    Sometime I created this little plugin to allow subsites under modx.

    To install create an new plugin called Subsites and enable the ’OnWebPageInit’ event then copy and paste the following code. Be sure to make the necessary modifications to the source:

    $e = &$modx->event;
    $subdomain = 'subdomain.yourdomain.com'; // your subdomain name here
    if($e->name=='OnWebPageInit') {
       $s = $_SERVER['HTTP_HOST'];
       if($s==$subdomain && $modx->documentIdentifier==$modx->config['site_start']){
          header('Location: index.php?id=6');
          exit;
       }
       else if($s==$subdomain){
           $modx->config['site_start'] = 6; // your start page here
           $modx->config['error_page'] = 6;	// your error page here
       }
    }


    Once the plugin is installed your next step is to make subdomain.yourdomain.com an alias of www.yourdomain.com.
      xWisdom
      www.xwisdomhtml.com
      The fear of the Lord is the beginning of wisdom:
      MODx Co-Founder - Create and do more with less.
      • 33337
      • 3,975 Posts
      Great work Raymond !! kiss

      Many people asked for this, and now they will be happy rolleyes

      Best regards,

      zi
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • 2762
        • 1,198 Posts
        Great!!
        I think it’s a nice feature to include in next release
          Free MODx Graphic resources and Templates www.tattoocms.it
          -----------------------------------------------------

          MODx IT  www.modx.it
          -----------------------------------------------------

          bubuna.com - Web & Multimedia Design
          • 6726
          • 7,075 Posts
          +1 this is really cool, even if I don’t need it (yet grin)
            .: COO - Commerce Guys - Community Driven Innovation :.


            MODx est l'outil id
            • 32241
            • 1,495 Posts
            Nice one!

            I just posted yesterday, and I received the complete solution in a day.

            Thanks xwisdom.

            Do you mind if I ask a little detailed about the code?

            &$modx->event

            That will fetch the current event by reference right?

            if($e->name=='OnWebPageInit') {

            Why do we need to check the current event again? I thought it will only be called when event is OnWebPageInit?

               if($s==$subdomain && $modx->documentIdentifier==$modx->config['site_start']){
                  header('Location: index.php?id=6');
                  exit;
               }
               else if($s==$subdomain){
                   $modx->config['site_start'] = 6; // your start page here
                   $modx->config['error_page'] = 6;	// your error page here
               }
            

            What is the first if conditional did? Checking the default page start?


            Hope I can start learning the current API in modX further, by starting from smaller plugin, and getting used to some other resources, which later lead to modules. Is there anyway to start understanding module better?

            Thank you

            Sincerely,
            Wendy Novianto
              Wendy Novianto
              [font=Verdana]PT DJAMOER Technology Media
              [font=Verdana]Xituz Media
              • 29635
              • 361 Posts
              Hi all. Great plugin Raymond!
              I’ve spent some time playing with it, and combining it with a modified version of Susan’s UltimateParent to make a sort of UltimateParentSubdomain. The idea is roughly:

              • set the subdomains’ "root"/landing page,
              • determine the subdomain,
              • find the ultimate parent using the subdomain root ID instead of 0.

              The problem is that links aren’t rendered with the subdomain. If I go to subdomain.boopaloo.com, the links on the page are for boopaloo.com/subdomain/item1.html, so once the visitor navigates away from the subdomain landing page, they’re no longer in the subdomain, which often isn’t what’s desired, and makes my snippet not work wink

              I’m guessing the solution might be in a plugin that loads on event OnFriendlyURLSettingsRender?, but I can’t get anything going. The plugin could check each link’s "ultimate subdomain parent" and apply the appropriate subdomain prefix to the link.

              So, if doc2 = subdomain2, then any link to content that is under doc2 gets its link rewritten. (When using alias paths, it’d also be nice to strip the first alias as well, so instead of subdomain2.boopaloo.com/doc2/folder/content it’d just be subdomain.boopaloo.com/folder/content. This isn’t quite as important but it’d be nice.)

              Does that make sense? Any ideas if OnFriendlyURLSettingsRender is the right thing to focus on, or any tips on how MODx makes the friendly URLs in the first place? I think this could be relatively simple, but I’m still new and don’t know where to look.

              Having subdomians function like this would be amazing, and would open the door to some pretty cool stuff kind of like WordPress Multi User. It would also allow an UltimateParent for subdomains, which would make menus within a subdomian much easier, and even stuff like having a simple snippet to display a different header/logo depending on the current subdomain. smiley
              Thanks all!
              Brett
                Need MODx Ecommerce? Try FoxyCart!
                • 32963
                • 1,732 Posts
                Quote from: wendy at Nov 18, 2005, 10:32 PM

                &$modx->event

                That will fetch the current event by reference right?
                That’s correct

                if($e->name=='OnWebPageInit') {

                Why do we need to check the current event again? I thought it will only be called when event is OnWebPageInit?

                Note here that we are checking for the name of the even by using $e->name. The plugin is only executed when anyone of the events it is listening to is invoked.


                   if($s==$subdomain && $modx->documentIdentifier==$modx->config['site_start']){
                      header('Location: index.php?id=6');
                      exit;
                   }
                   else if($s==$subdomain){
                       $modx->config['site_start'] = 6; // your start page here
                       $modx->config['error_page'] = 6;	// your error page here
                   }
                

                What is the first if conditional did? Checking the default page start?

                This will cause the plugin to redirect site_start request to the subdomain site_start page.

                Is there anyway to start understanding module better?

                You can have a look at our documentation:
                http://modxcms.com/developers-guide.html
                  xWisdom
                  www.xwisdomhtml.com
                  The fear of the Lord is the beginning of wisdom:
                  MODx Co-Founder - Create and do more with less.
                  • 32963
                  • 1,732 Posts
                  Quote from: The at Nov 19, 2005, 02:39 AM

                  The problem is that links aren’t rendered with the subdomain. If I go to subdomain.boopaloo.com, the links on the page are for boopaloo.com/subdomain/item1.html, so once the visitor navigates away from the subdomain landing page, they’re no longer in the subdomain, which often isn’t what’s desired, and makes my snippet not work wink


                  Hi Brett,

                  Are u usng firendly url paths?
                    xWisdom
                    www.xwisdomhtml.com
                    The fear of the Lord is the beginning of wisdom:
                    MODx Co-Founder - Create and do more with less.
                    • 29635
                    • 361 Posts
                    Hi Raymond. Yes I am. I’m using alias paths as well. ...
                    EDIT: Something goofy is happening with my DNS (or I *really* need some sleep wink ), but as of 10 minutes ago (and after hours of testing/banging my head against my desk) it does indeed rewrite the URLs to include the subdomain. Sorry to be stupid on this one.

                    EDIT again: I think I figured it out. Seems like once a page is loaded that is "unfriendly" (ie. /index.php?id=6), the subdomains no longer get attached to the links on the page. I have a weblink that points to one of its children, and I made that link "unfriendly"; so once that link like was clicked, the subdomain stopped appearing in the links. Changing the weblink to the appropriate friendly link works perfectly. Hopefully this helps somebody. Took me long enough to figure out.

                    Now I can focus on trying to get it to abstain from including the subdomain in links to content that’s "outside the subdomain" (as described above)... don’t hold your breath smiley
                    Thanks again Raymond. -Brett
                      Need MODx Ecommerce? Try FoxyCart!
                      • 32241
                      • 1,495 Posts
                      Quote from: xwisdom at Nov 20, 2005, 12:20 AM

                      Quote from: wendy at Nov 18, 2005, 10:32 PM



                         if($s==$subdomain && $modx->documentIdentifier==$modx->config['site_start']){
                            header('Location: index.php?id=6');
                            exit;
                         }
                         else if($s==$subdomain){
                             $modx->config['site_start'] = 6; // your start page here
                             $modx->config['error_page'] = 6;	// your error page here
                         }
                      

                      What is the first if conditional did? Checking the default page start?

                      This will cause the plugin to redirect site_start request to the subdomain site_start page.


                      I still don’t get it.

                      What I can interpret, if domain requested equal to $subdomain, then set the header to the desired doc id, and exit; else, if the the requested domain equal to $subdomain, then it will set the config vars of site start and error page into desired doc id.

                      From what I assume, the else if statement is the one that do the job, by changing the config site start and page error doc id, then what is the use of the first if statement? Why don’t we just move the header() into else if statement, and remove the if statement.

                      Sorry, if I ask something stupid.

                      Is there any possibility to include array support as the subdoain vars, and the plugin will loop throught the array of subdomain to determine whether the requested subdomain to be directed to the appropriate doc id that was assigned in the array. In fact, we can set the array key as the subdomain string, and let the value of array as the doc id for start page and error page, but I’m not to for sure whether php allowed an array key with a dot.

                      Thanks again for the help and reply.

                      PS: The developers docs is imrpoved from the one that I read a few weeks ago. Awesome! It helps me understand the way MODx work more than I know previously. Thank you guys!

                      regards,
                      Wendy Novianto
                        Wendy Novianto
                        [font=Verdana]PT DJAMOER Technology Media
                        [font=Verdana]Xituz Media