I'm trying to configure a rule in UrlRewrite that has 2 conditions:
HTTP_HOST
needs to match a certain domain (api.contoso.com)x-app-version
needs to be present in the HTTP requestbased on this info, I'd like to redirect to a different version of the API in the back-end.
Problem
The rule is behaving as expected on the first condition.
It kicks in when HTTP_HOST
matches api.contoso.com.
However, it ignores my custom x-app-version
header.
Assumption
So, I fear that a UrlRewrite condition only can be defined in combination with the limited set of predefined HTTP headers from the dropdown (HTTP_HOST
, REMOTE_ADDRESS
, REMOTE_HOST
, …)
Question Is assumption correct or should this be possible whatsoever? Is there a mistake in my config or other approach to have conditions based on a custom defined HTTP header?
<rule name="ARR_test2" enabled="false">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="api.contoso.com" />
<add input="{x-app-version}" pattern="1" />
</conditions>
<action type="Rewrite" url="https://FARM_apiv1/{R:0}" />
</rule>
Ok, I found out how to use custom HTTP headers in a UrlRewrite condition:
E.g.: in order to retrieve my custom header "x-app-version", I can use "HTTP_x_app_version". So my UrlRewrite config should look like this
<rule name="ARR_test2" enabled="false">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="api.contoso.com" />
<add input="{HTTP_x_app_version}" pattern="1" />
</conditions>
<action type="Rewrite" url="https://FARM_apiv1/{R:0}" />
</rule>
It's actually mentioned quite clear in the documentation: https://msdn.microsoft.com/en-us/library/ms524602(v=vs.90).aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With