IIS Rewrite Multiple URLS to Ports

iisiis-6iis-7iis-7.5rewrite

I have two processes/apps running on port 8888 & port 8890.

I can access them in my windows server with http://localhost:8888 & http://localhost:8890.

I am currently using IIS GUI for rewriting URLs. Application Request Routing(ARR) & URL Rewrite are installed.

I have been successful in rewriting or redirecting all requests which hit the server to one port – essentially I map '*' wildcard to 'http://localhost:8888/{R:0}' and it works when I access http://website!

How can I extend this to the following scenario:

http://website/solution1/ should redirect to port 8888 &
http://website/solution2/ should redirect to port 8890

Please help.

Best Answer

Something like this (in your web.config) should work:

<rule name="solution1" stopProcessing="true">
    <match url="^(solution1/)(.*)" />
    <action type="Rewrite" url="http://localhost:8888/{R:2}" />
</rule>
<rule name="solution2" stopProcessing="true">
    <match url="^(solution2/)(.*)" />
    <action type="Rewrite" url="http://localhost:8890/{R:2}" />
</rule>

IIRC, the {R:0} will match the entire URL, so you don't want that in this case. Instead, with the ( and ) you define 'capturing groups'; {R:2} will be everything after solution1/ or solution2/.

If you're set on using the IIS GUI, I hope you'll be able to find the fields that need to be filled; they are the same ones you already use, only with different parameters.