Reputation: 97
May i ask how do i rewrite url from
"https://hello.com/test/api/zoo/v1/animal?animal_record_no=20900016431"
to
"https://145.123.2.12:5000/api/zoo/v1/animal?animal_record_no=20900016431"
the query string "animal_record_no" is optional.
Basically i just want to remove the "test" from the url and change the ip address.
This is what i have now, but it does not forward the query string:
<rule name="ReverseProxyInboundRule3" stopProcessing="true">
<match url="^test/([_0-9a-zA-Z-]+)/([_0-9a-zA-Z-]+)/([_0-9a-zA-Z-]+)/([_0-9a-zA-Z-]+)/?$" />
<action type="Rewrite" url="http://145.123.2.12:5000/{R:1}/{R:2}/{R:3}/{R:4}" />
<conditions>
</conditions>
</rule>
If i were to use redirect, i got a HTTP/1.1 301 Moved Permanently error
<rule name="ReverseProxyInboundRule3" enabled="true" stopProcessing="true"> <match url=".*test/(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="iex.odp.gov.sg" />
</conditions>
<action type="Redirect" url="http://145.123.2.12:5000/{R:1}" />
Thanks for the help.
Upvotes: 2
Views: 3338
Reputation: 3974
Add URL Rewrite like below:
We don’t need to add rules for the query string, we just need to enable "Append query string", IIS will help us rewrite query string.
The configuration in web.config is as follows:
<rewrite>
<rules>
<rule name="Test">
<match url="(.*)(test)/(api)/(zoo)/(v1)/(animal)" />
<action type="Rewrite" url="https://145.123.2.12:5000/{R:3}/{R:4}/{R:5}/{R:6}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
If the two ULRs are not pointing to the same host, you also need to enable reverse proxy.
Feel free to let me know if the problem persists.
Upvotes: 3