We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16902
    • 7 Posts
    ContextRouter works fine, however, doesn't seem to solve one issue concerning domains different versions of image banks, css versions, favicons etc. I tried to put them in subfolders of root or assets, so that each domain context will have its own sets, but cannot get it routed properly. I've read a few comments on it here in Forums, but don't grasp how it could be implemented in Modx Cloud, how to use rewrite rules in nginx if necessary (?), to use real or pseudo subfolders and so on. Also tried to copy config.cor.php and index.php (altering 'web' to 'mycontext') to subfolders respectively, so far no results.

    Would be nice with a step-by-step guide how to implement this with the help of ContextRouter and other plugins/snippets.
    Following comments give hints, but you should be a developer (I'm not) to implement it in your Modx Cloud installation:
    http://forums.modx.com/thread/?thread=51346.&i=1&page=1
    http://forums.modx.com/thread/?thread=57691.&i=1&page=1

    Thanks for any comments, Leif Hjerpe

    This question has been answered by leif.hjerpe. See the first response.

      • 16902
      • 7 Posts
      Now I tried with a static resource - just for hosting a simple site with index.htm, a few menu pages and subfolders for css, images, favicon etc
      - and Yes, it works, more simple than I guessed.

      The only change I had to make was in <base href="[[++site_url]]" />
      in this (static resource) case <base href="http://domain-name.tld/sub/index.htm" />
      similarly for the other *.htm pages of the menu ---
      and alla relative links for css etc works with FURL enabled (ver 2.2.8 in my clouds). First of all, of course, was to create the subfolder and make it base_url in my Context - value sub/ (of Media root). Now my Media root is clean and shows only one sub folder, and I may continue to finish the site for 'web' context, and hopefully parallell (non static) sites in other sub folders.

      I guess I could manage it for other resources of documents (non static) as well? How to manage [[++site_url]] for domains in subfolders, so it will route their own css, images, favicons etc subfolders? Like in the example above.
      Any comments? /Leif
        • 16902
        • 7 Posts
        It works! But only if I deactivate FURL (in System settings).
        And with ContextRouter installed it should not be necessary to copy config.php or config.cor.php to the sub folder. I deleted these files (altered as described above) in the sub folders, and no difference, each context catches its sub folders. Neither need to add any rewrite rules to nginx.
        - However, only it FURL is disabled! If enabled, I get this message from Chrome browser:
        "The webpage at http://demo.xnova.se/services/ has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer."
        - Similarly from FFox:
        "Firefox has detected that the server is redirecting the request for this address in a way that will never complete."

        Above described solution suits me good, as it's simple and including a logical structure, if I only could get FURL working with it. So it's my only question now.

        Or are there other better solutions? However, it should not be too complicated to set up, compared to this pretty simple set up including ContextRouter.
        Regards, Leif
        • Make sure the folders do not physically exist on the filesystem.

          I have no experience with nginx but with apache I use the following rewrites:

          # Establish site root
          RewriteEngine On
          RewriteBase /
          
          RewriteCond %{HTTP_HOST} !^assets\.
          RewriteCond %{HTTP_HOST} !^mail\.
          RewriteCond %{HTTP_HOST} !^operations\.
          RewriteCond %{HTTP_HOST} !^www\.
          RewriteRule ^(.*)$ http://www.PRIMARY-DOMAIN.com/$1 [R=301,L]
          
          # The Friendly URLs part
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]


          assets is utilized for static content and CloudFlare CDN
          operations is a fully functional subdomain
          etc
            Get your copy of MODX Revolution Building the Web Your Way http://www.sanitypress.com/books/modx-revolution-building-the-web-your-way.html

            Check out my MODX || xPDO resources here: http://www.shawnwilkerson.com
            • 16902
            • 7 Posts
            Thanks Shawn
            It should be translatable, this htaccess, to nginx rewrite rules, if they'll give some help at Modx Cloud (usually they give). Could you explain the conditions more in detail?

            "Make sure the folders do not physically exist on the filesystem":
            Where should they be? Now, if I disable FURL, all the content of my sub folders are accessible, like

            css/domain1/ ...
            favicon/domain1/ ...
            images/domain1/ ...
            js/domain1/ ...
            ... etc
            css/domain2/ ...
            favicon/domain2/ ...
            images/domain2/ ...
            js/domain2/ ...
            ... etc
            for each domain (routed by ContextRouter), so content may be chosen by base_url set in ContextRouter, and the folders exist physically on the filesystem. You just put your site_url in any suitable sub folder, and it'll work the same way as in root = PRIMARY-DOMAIN.com

            "assets is utilized for static content and CloudFlare CDN
            operations is a fully functional subdomain
            etc"
            Couldn't 'assets', 'operations' etc be named according to your flavor? Like in my example above? Or it wouldn't be "fully functional"?

            Maybe it would work under FURL if I'll just get your htaccess file translated to Nginx? Or are you talking about other "pseudo folders"? Or maybe about a system without ContextRouter?
            I'll try it, but first wait for your response.
            Thanks again, Leif
            • The folders can not be on the file system for the subdomains, as that will override modx serving them unless that is the desired affect such as my assets folder which is not defined in a context anyway so ContextRouter doesn't even know its there.

              Per my example, you should not have a domain.com/operations directory as the primary modx index.php will be serving it via contextRouter


              all of the
              RewriteCond %{HTTP_HOST} !^assets\.
              RewriteCond %{HTTP_HOST} !^mail\.
              RewriteCond %{HTTP_HOST} !^operations\.
              RewriteCond %{HTTP_HOST} !^www\.


              lines simply mean if {HTTP_HOST) is not (fill in the blank) then do next test until it forces the seo friendly www.domain.com. In essence, ignore this line and move on if the user typed this.

              I just place my css and js in the assets folder.... assets/css/filename.css etc.


              Hope this helps.
                Get your copy of MODX Revolution Building the Web Your Way http://www.sanitypress.com/books/modx-revolution-building-the-web-your-way.html

                Check out my MODX || xPDO resources here: http://www.shawnwilkerson.com
                • 16902
                • 7 Posts
                "I just place my css and js in the assets folder.... assets/css/filename.css etc."
                If I want to route my css (and others mentioned) files, I have to name them according to the domain using them, as in my subfolders.

                Should each contexts base_url be according to assets folder like assets/domain1/ + assets/domain2/ etc?
                Each domain must choose its files respectively, as they differ from domain to domain. I grasp most of your description, but not how and where I put the files related to each ones domain. It should resemble something like:
                assets/domain1/css/filename1.css + assets/domain1/js/filename1.js ... etc
                assets/domain2/css/filename2.css + assets/domain2/js/filename2.js ... etc
                etc for following domains.

                I must correct myself, my subfolders above (reply #4) were not correct (a typo), but are (could also be without sub/):
                sub/domain1/css/file1.css ... sub/domain1/favicons/file1.js ... etc
                sub/domain2/css/file2.css ... sub/domain2/favicons/file2.js ... etc
                ...
                or it would not work according to base_url = sub/domain1/ ... base_url = sub/domain2/ ... etc (or /domain1/ ...), which I've set up for each context, used by contextRouter as I understand.

                Are we talking about the same issue, precisely, or did I miss something in your explanation?
                For the Modx Cloud environment (Nginx etc) I wait for some guidance from their support, and I'll inform you. However, I guess you have a little more to elucidate for a novice in this field.
                Leif
                  • 16902
                  • 7 Posts
                  Shawn
                  This seems to be the translation of your htaccess file to Nginx - from Modx Cloud Support, Mike Schell:
                  if ($host ~ ^(?!(assets|mail|operations|www)\.)) {
                      rewrite ^ $scheme://www.PRIMARY-DOMAIN.com$uri permanent;
                  }
                  location / {
                    try_files $uri $uri/ @modx-rewrite;
                  }
                  


                  We will try something similar, because in this case all domains are redirected to the primary, which was not the aim.
                  I think you have pointed to a correct solution, however, I don't grasp so much of these rewrite rules (and my English is not the best).
                  Leif
                  • discuss.answer
                    • 16902
                    • 7 Posts
                    Issue solved!
                    (Thanks for your answers, Shawn, they helped to understand this issue more deep. One question I still don't grasp: how does ^operations\. work, is it generated by contextRouter?)

                    Mike Shell at Modx Cloud support had a similar issue, so he gave me following Nginx rewrite rules, and now all my domains in one Manager work together in harmony:
                    # rewrite js, css and media requests for some.domain.com
                    if ($host ~* ^some.domain.com) {
                        rewrite ^/(js|css|media)/(.*)$ /somedomain/$1/$2 last;}
                    
                    location / 
                    {try_files $uri $uri/ @modx-rewrite;} 
                    }
                    
                    Based on this I made my own:
                    
                    # rewrite css|drive|im|js|media requests for vision.portraits.se 
                    if ($host ~* ^vision.portraits.se) 
                    {rewrite ^/(css|drive|im|js|media)/(.*)$ /2.vision/$1/$2 last;}
                    
                    # rewrite css|drive|im|js|media requests for my.xnova.se 
                    if ($host ~* ^my.xnova.se) 
                    {rewrite ^/(css|drive|im|js|media)/(.*)$ /3.my/$1/$2 last;}
                    
                    # rewrite css|drive|im|js|media for guide.xnova.se 
                    if ($host ~* ^guide.xnova.se) 
                    {rewrite ^/(css|drive|im|js|media)/(.*)$ /0.guide/$1/$2 last;}
                    
                    # rewrite css|drive|im|js|media requests for demo.xnova.se 
                    if ($host ~* ^demo.xnova.se) 
                    {rewrite ^/(css|drive|im|js|media)/(.*)$ /1.rikt/$1/$2 last;} 
                    # test bed for publishing following domain:
                    
                    # rewrite css|drive|im|js|media requests for rikt.se 
                    #if ($host ~* ^rikt.se) 
                    #{rewrite ^/(css|drive|im|js|media)/(.*)$ /1.rikt/$1/$2 last;}
                    
                    location / 
                    {try_files $uri $uri/ @modx-rewrite;} 
                    }
                    


                    You may translate it to Apache rewrite rules, so you see how they solve this issue, which I guess I didn't explain very clear for you?
                    Sorry I'm late with this answer, but I was too occupied with one client last 3 weeks. / Leif