IIS URL Rewrite main entry site redirect to blue / green entry
First, I am not great at writing regular expressions, so I apologize for that.
I am trying to setup IIS to rewrite URLs from one main entry to a secondary blue / green entry site. As part of a multi-tenancy setup users are redirected by US state abbreviations. For now, we will only be looking for the 2 letters after the domain name. All traffic will be coming in to the main entry site https://dev.app.com
and redirected to the appreciate state's URL
For example:
http://dev.app.com/ca
or http://dev.app.com/ny
By default, users that come into the root of the site http://dev.app.com
will be automatically redirected to http://dev.app.com/ca
. CA is our default state.
Each state has its own blue / green entry site. For example: http://ca.app.entry
. The blue / green entry sites have a reverse proxy rewrite rule to redirect traffic to whatever site is currently running. The blue / green rewrite rule is updated during deployment.
Also, each state has its own API. For example: http://ca.api.com
. The main entry URL would look like this: https://dev.app.com/ca/ext
and it would forward traffic to the correct state's API.
I have been trying to setup the rewrite rules to trap the state abbreviation and also look for the ext
if it exists and forward to the appropriate AI site.
For the default URL I started out by creating a redirect rule that comes before the rewrite rules
<httpRedirect enabled="true">
<add wildcard="/" destination="/ca" />
</httpRedirect>
The next rule I am trying to trap the state abbreviation:
<rule name="StateRewrite" stopProcessing="true">
<match url="/([a-z]{2})/$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="http://{R:1}.app.entry" logRewrittenUrl="true" />
</rule>
Testing the expression I get the proper 2 letter state abbreviation as long as there is nothing after the [state]/. So http://dev.app.com/ca/someOtherqueryString does not produce a match. Going to http://dev.app.com/ca/ does not seem to forward traffic to [state].app.entry/[state]. If I go directly to the state's entry site it works. So, going to ca.app.entry/ca routes to the proper blue / green site. Looking at the logs it doesn't seem to be constructing the the entire URL. I am only seeing the /[state]/
in the log: 2018-12-27 16:57:25 127.0.0.1 GET /ca/
For the API site I tried a pattern rule like this (.*)/ext/(.*)
. The rule comes after the state abbreviation rule, but it is still not routing to the proper state API site.
I could use some help constructing the rules and how they need to be ordered.
regex iis url-rewriting
add a comment |
First, I am not great at writing regular expressions, so I apologize for that.
I am trying to setup IIS to rewrite URLs from one main entry to a secondary blue / green entry site. As part of a multi-tenancy setup users are redirected by US state abbreviations. For now, we will only be looking for the 2 letters after the domain name. All traffic will be coming in to the main entry site https://dev.app.com
and redirected to the appreciate state's URL
For example:
http://dev.app.com/ca
or http://dev.app.com/ny
By default, users that come into the root of the site http://dev.app.com
will be automatically redirected to http://dev.app.com/ca
. CA is our default state.
Each state has its own blue / green entry site. For example: http://ca.app.entry
. The blue / green entry sites have a reverse proxy rewrite rule to redirect traffic to whatever site is currently running. The blue / green rewrite rule is updated during deployment.
Also, each state has its own API. For example: http://ca.api.com
. The main entry URL would look like this: https://dev.app.com/ca/ext
and it would forward traffic to the correct state's API.
I have been trying to setup the rewrite rules to trap the state abbreviation and also look for the ext
if it exists and forward to the appropriate AI site.
For the default URL I started out by creating a redirect rule that comes before the rewrite rules
<httpRedirect enabled="true">
<add wildcard="/" destination="/ca" />
</httpRedirect>
The next rule I am trying to trap the state abbreviation:
<rule name="StateRewrite" stopProcessing="true">
<match url="/([a-z]{2})/$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="http://{R:1}.app.entry" logRewrittenUrl="true" />
</rule>
Testing the expression I get the proper 2 letter state abbreviation as long as there is nothing after the [state]/. So http://dev.app.com/ca/someOtherqueryString does not produce a match. Going to http://dev.app.com/ca/ does not seem to forward traffic to [state].app.entry/[state]. If I go directly to the state's entry site it works. So, going to ca.app.entry/ca routes to the proper blue / green site. Looking at the logs it doesn't seem to be constructing the the entire URL. I am only seeing the /[state]/
in the log: 2018-12-27 16:57:25 127.0.0.1 GET /ca/
For the API site I tried a pattern rule like this (.*)/ext/(.*)
. The rule comes after the state abbreviation rule, but it is still not routing to the proper state API site.
I could use some help constructing the rules and how they need to be ordered.
regex iis url-rewriting
add a comment |
First, I am not great at writing regular expressions, so I apologize for that.
I am trying to setup IIS to rewrite URLs from one main entry to a secondary blue / green entry site. As part of a multi-tenancy setup users are redirected by US state abbreviations. For now, we will only be looking for the 2 letters after the domain name. All traffic will be coming in to the main entry site https://dev.app.com
and redirected to the appreciate state's URL
For example:
http://dev.app.com/ca
or http://dev.app.com/ny
By default, users that come into the root of the site http://dev.app.com
will be automatically redirected to http://dev.app.com/ca
. CA is our default state.
Each state has its own blue / green entry site. For example: http://ca.app.entry
. The blue / green entry sites have a reverse proxy rewrite rule to redirect traffic to whatever site is currently running. The blue / green rewrite rule is updated during deployment.
Also, each state has its own API. For example: http://ca.api.com
. The main entry URL would look like this: https://dev.app.com/ca/ext
and it would forward traffic to the correct state's API.
I have been trying to setup the rewrite rules to trap the state abbreviation and also look for the ext
if it exists and forward to the appropriate AI site.
For the default URL I started out by creating a redirect rule that comes before the rewrite rules
<httpRedirect enabled="true">
<add wildcard="/" destination="/ca" />
</httpRedirect>
The next rule I am trying to trap the state abbreviation:
<rule name="StateRewrite" stopProcessing="true">
<match url="/([a-z]{2})/$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="http://{R:1}.app.entry" logRewrittenUrl="true" />
</rule>
Testing the expression I get the proper 2 letter state abbreviation as long as there is nothing after the [state]/. So http://dev.app.com/ca/someOtherqueryString does not produce a match. Going to http://dev.app.com/ca/ does not seem to forward traffic to [state].app.entry/[state]. If I go directly to the state's entry site it works. So, going to ca.app.entry/ca routes to the proper blue / green site. Looking at the logs it doesn't seem to be constructing the the entire URL. I am only seeing the /[state]/
in the log: 2018-12-27 16:57:25 127.0.0.1 GET /ca/
For the API site I tried a pattern rule like this (.*)/ext/(.*)
. The rule comes after the state abbreviation rule, but it is still not routing to the proper state API site.
I could use some help constructing the rules and how they need to be ordered.
regex iis url-rewriting
First, I am not great at writing regular expressions, so I apologize for that.
I am trying to setup IIS to rewrite URLs from one main entry to a secondary blue / green entry site. As part of a multi-tenancy setup users are redirected by US state abbreviations. For now, we will only be looking for the 2 letters after the domain name. All traffic will be coming in to the main entry site https://dev.app.com
and redirected to the appreciate state's URL
For example:
http://dev.app.com/ca
or http://dev.app.com/ny
By default, users that come into the root of the site http://dev.app.com
will be automatically redirected to http://dev.app.com/ca
. CA is our default state.
Each state has its own blue / green entry site. For example: http://ca.app.entry
. The blue / green entry sites have a reverse proxy rewrite rule to redirect traffic to whatever site is currently running. The blue / green rewrite rule is updated during deployment.
Also, each state has its own API. For example: http://ca.api.com
. The main entry URL would look like this: https://dev.app.com/ca/ext
and it would forward traffic to the correct state's API.
I have been trying to setup the rewrite rules to trap the state abbreviation and also look for the ext
if it exists and forward to the appropriate AI site.
For the default URL I started out by creating a redirect rule that comes before the rewrite rules
<httpRedirect enabled="true">
<add wildcard="/" destination="/ca" />
</httpRedirect>
The next rule I am trying to trap the state abbreviation:
<rule name="StateRewrite" stopProcessing="true">
<match url="/([a-z]{2})/$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="http://{R:1}.app.entry" logRewrittenUrl="true" />
</rule>
Testing the expression I get the proper 2 letter state abbreviation as long as there is nothing after the [state]/. So http://dev.app.com/ca/someOtherqueryString does not produce a match. Going to http://dev.app.com/ca/ does not seem to forward traffic to [state].app.entry/[state]. If I go directly to the state's entry site it works. So, going to ca.app.entry/ca routes to the proper blue / green site. Looking at the logs it doesn't seem to be constructing the the entire URL. I am only seeing the /[state]/
in the log: 2018-12-27 16:57:25 127.0.0.1 GET /ca/
For the API site I tried a pattern rule like this (.*)/ext/(.*)
. The rule comes after the state abbreviation rule, but it is still not routing to the proper state API site.
I could use some help constructing the rules and how they need to be ordered.
regex iis url-rewriting
regex iis url-rewriting
asked Dec 27 '18 at 17:59
DDiVita
2,468247100
2,468247100
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
the following regex will return 2 chars from the end of the string [a-z]{2}$
if there can be a / after that then it would be like this [a-z]{2}/?$
that is for regex as for the rewrite rules it should work but i am not sure exactly how the rewrites work with substitutions so hope this helps
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53949052%2fiis-url-rewrite-main-entry-site-redirect-to-blue-green-entry%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
the following regex will return 2 chars from the end of the string [a-z]{2}$
if there can be a / after that then it would be like this [a-z]{2}/?$
that is for regex as for the rewrite rules it should work but i am not sure exactly how the rewrites work with substitutions so hope this helps
add a comment |
the following regex will return 2 chars from the end of the string [a-z]{2}$
if there can be a / after that then it would be like this [a-z]{2}/?$
that is for regex as for the rewrite rules it should work but i am not sure exactly how the rewrites work with substitutions so hope this helps
add a comment |
the following regex will return 2 chars from the end of the string [a-z]{2}$
if there can be a / after that then it would be like this [a-z]{2}/?$
that is for regex as for the rewrite rules it should work but i am not sure exactly how the rewrites work with substitutions so hope this helps
the following regex will return 2 chars from the end of the string [a-z]{2}$
if there can be a / after that then it would be like this [a-z]{2}/?$
that is for regex as for the rewrite rules it should work but i am not sure exactly how the rewrites work with substitutions so hope this helps
answered Dec 28 '18 at 11:45
markorial
212
212
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53949052%2fiis-url-rewrite-main-entry-site-redirect-to-blue-green-entry%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown