I would like to host multiple APIs in IIS which should all be accessible via the standard http port 80. Internally IIS should then forward this request to some other local port e.g.:
http://someip:80/api1/request1 -> http://localhost:1234/request1
http://someip:80/api2/request2 -> http://localhost:5678/request2
Im trying to achieve this by using URLRewrite with the following rule
As far as I understand what I've set up should
a) match any request
b) check if the QUERY_STRING matches /bosswrapper/(.) and place the (.) content in {C:1}
c) replace that request with http://localhost:12345/{C:1}
so that means http://somehost/bosswrapper/foo/bar should become http://localhost:12345/foo/bar.
When I call http://localhost:12345/foo/bar directly everything works, when I call http://somehost/bosswrapper/foo/bar it does not. What am I missing?
CodePudding user response:
http://somehost/bosswrapper/foo/bar -> http://localhost:12345/foo/bar
Your rewrite rule is not exactly correct, try the following rewrite rule in web.cofig
:
<rewrite>
<rules>
<rule name="my rule">
<match url="bosswrapper/(.*)" />
<action type="Rewrite" url="http://localhost:12345/{R:1}" />
</rule>
</rules>
</rewrite>
The QUERY_STRING
server variable match the parameter string of the URL, should not be used to match the path part of the URL.
Also your rewrite rule should be created on the site where the hostname is somehost
.