Hello, i have the following specifc doubts:
1st: it`s possible to concat variables? i mean i want to do an if statement like this:
if ($host$request_uri ~ ^https?:\/{2}([^w]{3})(.*)\/$) {
set $redirect_option 3
}
But so far i wasn`t able to get the full url (domain + uri), only one or other and this is crippling me :/
2nd: Trying to find out a solution (assuming i can`t have the full url to match with regex), i`ve tried something like this:
XYZ are conditions ommited here
set $redirect_condition 0;
if ($force_ssl = XYZ) {
set $redirect_condition 1;
}
if ($request_uri ~ ^/healthcheck(.*)$) {
set $redirect_condition 0;
}
if ($request_uri ~ ^/(.*)/$) {
set $redirect_condition 2;
}
if ($host ~ ^https?:\/\/[^w](.*)) {
set $redirect_condition "${redirect_condition}3";
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
if ($http_x_forwarded_proto = "https") {
add_header Strict-Transport-Security "max-age=60; includeSubDomains";
}
if ($redirect_condition = 23) {
rewrite ^/(.*)/$ https://www.anydomain.com/$1 permanent;
}
if ($redirect_condition = 1) {
rewrite ^ https://$host$request_uri? permanent;
}
if ($redirect_condition = 2) {
rewrite ^/(.*)/$ https://$host/$1 permanent;
}
Any suggestion to make it works? TY
1st: it`s possible to concat variables? i mean i want to do an if statement like this:
if ($host$request_uri ~ ^https?:\/{2}([^w]{3})(.*)\/$) {
set $redirect_option 3
}
But so far i wasn`t able to get the full url (domain + uri), only one or other and this is crippling me :/
2nd: Trying to find out a solution (assuming i can`t have the full url to match with regex), i`ve tried something like this:
XYZ are conditions ommited here
set $redirect_condition 0;
if ($force_ssl = XYZ) {
set $redirect_condition 1;
}
if ($request_uri ~ ^/healthcheck(.*)$) {
set $redirect_condition 0;
}
if ($request_uri ~ ^/(.*)/$) {
set $redirect_condition 2;
}
if ($host ~ ^https?:\/\/[^w](.*)) {
set $redirect_condition "${redirect_condition}3";
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
if ($http_x_forwarded_proto = "https") {
add_header Strict-Transport-Security "max-age=60; includeSubDomains";
}
if ($redirect_condition = 23) {
rewrite ^/(.*)/$ https://www.anydomain.com/$1 permanent;
}
if ($redirect_condition = 1) {
rewrite ^ https://$host$request_uri? permanent;
}
if ($redirect_condition = 2) {
rewrite ^/(.*)/$ https://$host/$1 permanent;
}
Any suggestion to make it works? TY