We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50960
    • 17 Posts
    I have a few subdomains setup in my domain manager. I have ContextRouter installed in the manager. It has worked beautifully in the past. More recently I have added a webrule rewrite to force HTTPS. With this rule installed the subdomains no longer function correctly. They direct to the main URL of the website. Any guidance or others have this issue before? I have attached my Nginx Web rewrites for viewing. I have also setup a manual redirect to a subfolder which works either way.

    trying to get uk.domain.com to work with the ContextRouter.

    rewrite_log on;
        error_log /c2290/log/rewrite.log notice;
    
    # subdomain rewrites
    if ($host = "example.domain.com") {
      rewrite ^ https://www.domain.com/pages/example/$uri permanent;
    }
    
    location ~*  \.(jpg|jpeg|png|gif|ico|css|js|webm|ogv|mp4)$ {
       expires 20d;
    }
    
    # Tells the browser to always force SSL. 
    # add_header Strict-Transport-Security "max-age=31536000; includeSubdomains"; 
    if ($scheme != "https") {
        rewrite ^ https://www.domain.com$uri permanent;
    }
    if ($host != "www.domain.com") {
        rewrite ^ https://www.domain.com$uri permanent;
    }
    
    location / {
        try_files $uri $uri/ @modx-rewrite;
    }
    

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

      Tink!
      • 5430
      • 247 Posts
      I suck at NGINX rules, to be truthful, but first glance it seems like any non https request is going to get routed to your primary domain, at which point, it's no longer a request for your subdomain. I think you could change:
      if ($scheme != "https") {
          rewrite ^ https://www.domain.com$uri permanent;
      }
      

      to:
      if ($scheme != "https") {
          rewrite ^ https://$host$uri permanent;
      }
      
        • 50960
        • 17 Posts
        Quote from: claytonk at Apr 18, 2016, 07:33 PM
        I suck at NGINX rules, to be truthful, but first glance it seems like any non https request is going to get routed to your primary domain, at which point, it's no longer a request for your subdomain. I think you could change:

        Thanks for your input clayton. Where the update you have suggested works great (and will use that method going forward), the update produces the same result. No response from my redirected subdomain a-records.
          Tink!
          • 5430
          • 247 Posts
          Quote from: smorris at Apr 19, 2016, 03:24 PM
          No response from my redirected subdomain a-records.

          So I know this is a really stupid question, but just to be sure, you are routing all of these subdomains to the same A-record, correct? Is this site running on MODX Cloud? If so, I assume you setup your cloud's domain settings to include the subdomains you're using?
            • 5430
            • 247 Posts
            Yeah, those were stupid questions, as I read your original post it looks like everything was running fine until the introduction of https. Just thinking here, but the site_url context setting for each context should be updated to include the https, I assume you've done that already?
              • 50960
              • 17 Posts
              Quote from: claytonk at Apr 19, 2016, 07:45 PM
              Yeah, those were stupid questions, as I read your original post it looks like everything was running fine until the introduction of https. Just thinking here, but the site_url context setting for each context should be updated to include the https, I assume you've done that already?

              Not dumb questions. Can never assume to much. But yes, it has all been setup and was working before.

              base_url = /
              http_host = uk.domain.com
              site_start = 256
              site_url = https://uk.domain.com

              I have been spinning my head in circles on this. I also just tested to see if I remove ONLY the listed code from near the bottom (line 18 - 20 above).

              if ($host != "www.domain.com") {
                  rewrite ^ https://www.domain.com$uri permanent;
              }
               


              I can get it to work then, However the site styles and site itself goes haywire and can't authenticate, but the context subdomains work. :/

              I appreciate your help, I may have to submit a modxcloud service support ticket for this. They have been helpful on the ticket level but may be a little deeper of an issue.
                Tink!
              • discuss.answer
                • 50960
                • 17 Posts
                I have solved this issue. Posting my results if anyone stumbles upon this thread and needs help.

                Claytonk had a pretty good suggestion in the thread, needed one more additional edit to work. After revisiting it after a couple months I saw my issue and was able to correct it.

                The objective was to have a forced HTTPS (secure) url. that redirects to https://www.domain.com (NOT be able to go to https://domain.com) while still being able to utilize subdomain's for other contexts (multilingual site essentially).

                nginx rewrite:
                if ($scheme != "https") {
                    rewrite ^ https://$host$uri permanent;
                }
                
                if ($host = "domain.com") {
                    return 301 $scheme://www.domain.com$request_uri;
                }
                
                location / {
                    try_files $uri $uri/ @modx-rewrite;
                }
                


                Context Setup with ModxCloud domains setup as well:
                base_url = /
                http_host = uk.domain.com
                site_start = 256
                site_url = https://uk.domain.com
                  Tink!
                  • 54330
                  • 1 Posts
                  for data related queries, contact UAE Data Recovery