<![CDATA[ HTTPS rewrite rule (Nginx) not working correctly with ContextRouter and subdomains - My Forums]]> https://forums.modx.com/thread/?thread=99971 <![CDATA[HTTPS rewrite rule (Nginx) not working correctly with ContextRouter and subdomains]]> https://forums.modx.com/thread/99971/https-rewrite-rule-nginx-not-working-correctly-with-contextrouter-and-subdomains#dis-post-540624
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;
}

]]>
smorris Apr 18, 2016, 12:55 PM https://forums.modx.com/thread/99971/https-rewrite-rule-nginx-not-working-correctly-with-contextrouter-and-subdomains#dis-post-540624
<![CDATA[Re: HTTPS rewrite rule (Nginx) not working correctly with ContextRouter and subdomains]]> https://forums.modx.com/thread/99971/https-rewrite-rule-nginx-not-working-correctly-with-contextrouter-and-subdomains#dis-post-559180 UAE Data Recovery]]> rossgeller99 Jun 22, 2018, 05:00 AM https://forums.modx.com/thread/99971/https-rewrite-rule-nginx-not-working-correctly-with-contextrouter-and-subdomains#dis-post-559180 <![CDATA[Re: HTTPS rewrite rule (Nginx) not working correctly with ContextRouter and subdomains (Best Answer)]]> https://forums.modx.com/thread/99971/https-rewrite-rule-nginx-not-working-correctly-with-contextrouter-and-subdomains#dis-post-552785
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]]>
smorris Jul 25, 2017, 05:23 PM https://forums.modx.com/thread/99971/https-rewrite-rule-nginx-not-working-correctly-with-contextrouter-and-subdomains#dis-post-552785
<![CDATA[Re: HTTPS rewrite rule (Nginx) not working correctly with ContextRouter and subdomains]]> https://forums.modx.com/thread/99971/https-rewrite-rule-nginx-not-working-correctly-with-contextrouter-and-subdomains#dis-post-540678 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.]]>
smorris Apr 19, 2016, 03:01 PM https://forums.modx.com/thread/99971/https-rewrite-rule-nginx-not-working-correctly-with-contextrouter-and-subdomains#dis-post-540678
<![CDATA[Re: HTTPS rewrite rule (Nginx) not working correctly with ContextRouter and subdomains]]> https://forums.modx.com/thread/99971/https-rewrite-rule-nginx-not-working-correctly-with-contextrouter-and-subdomains#dis-post-540677 claytonk Apr 19, 2016, 02:45 PM https://forums.modx.com/thread/99971/https-rewrite-rule-nginx-not-working-correctly-with-contextrouter-and-subdomains#dis-post-540677 <![CDATA[Re: HTTPS rewrite rule (Nginx) not working correctly with ContextRouter and subdomains]]> https://forums.modx.com/thread/99971/https-rewrite-rule-nginx-not-working-correctly-with-contextrouter-and-subdomains#dis-post-540671 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?]]>
claytonk Apr 19, 2016, 02:27 PM https://forums.modx.com/thread/99971/https-rewrite-rule-nginx-not-working-correctly-with-contextrouter-and-subdomains#dis-post-540671
<![CDATA[Re: HTTPS rewrite rule (Nginx) not working correctly with ContextRouter and subdomains]]> https://forums.modx.com/thread/99971/https-rewrite-rule-nginx-not-working-correctly-with-contextrouter-and-subdomains#dis-post-540660 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.]]>
smorris Apr 19, 2016, 10:24 AM https://forums.modx.com/thread/99971/https-rewrite-rule-nginx-not-working-correctly-with-contextrouter-and-subdomains#dis-post-540660
<![CDATA[Re: HTTPS rewrite rule (Nginx) not working correctly with ContextRouter and subdomains]]> https://forums.modx.com/thread/99971/https-rewrite-rule-nginx-not-working-correctly-with-contextrouter-and-subdomains#dis-post-540630
if ($scheme != "https") {
    rewrite ^ https://www.domain.com$uri permanent;
}

to:
if ($scheme != "https") {
    rewrite ^ https://$host$uri permanent;
}
]]>
claytonk Apr 18, 2016, 02:33 PM https://forums.modx.com/thread/99971/https-rewrite-rule-nginx-not-working-correctly-with-contextrouter-and-subdomains#dis-post-540630