3
votes

I'm using the URL Rewrite feature in IIS7. I have set up a website on port 80 with some URL rewrite rules.

The first rule needs to point to a web application on port 8090 and the other rule needs to point to a web application on port 8091.

The rules need to be configured so that:

  1. http://localhost/ rewrites to http://localhost:8090
  2. http://localhost/test rewrites to http://localhost:8091.

Here is the rules that I'm using:

<system.webServer>
    <rewrite>
        <rules>
            <clear />
            <rule name="Site2" enabled="true" stopProcessing="true">
                <match url="^.*/test/.*" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                <action type="Rewrite" url="http://{HTTP_HOST}:8091/{R:0}" />
            </rule>
            <rule name="Site1" enabled="true" stopProcessing="true">
                <match url=".*" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                <action type="Rewrite" url="http://{HTTP_HOST}:8090/{R:0}" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

I'll mention that the "Site1" rule is working. If I go to http://localhost/, I am presented with the web application hosted on port 8090. If I go to http://localhost/test, I am presented with a 404 error.

2
Did you ever figure this out? I'm having the exact same problem.InteXX
You can find my solution below. Hope this helps.Lydon

2 Answers

0
votes

I did end up getting this working as required. The following is the web.config file used on my default website hosted on port 80. What this allows me to do is browse to http://my.domain.com/test1 and get the site that is hosted on http://localhost:8093/test1.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <httpRedirect enabled="false" destination="https://my.domain.com" exactDestination="true" />
        <rewrite>
            <rules>
                <clear />
                <rule name="Redirect to correct test1 address" stopProcessing="true">
                    <match url="^test1$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Redirect" url="http://my.domain.com/test1/" />
                </rule>
                <rule name="Redirect to correct test2 address" stopProcessing="true">
                    <match url="^test2$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Redirect" url="http://my.domain.com/test2/" />
                </rule>
                <rule name="Redirect to correct test3 address" stopProcessing="true">
                    <match url="^test3$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Redirect" url="http://my.domain.com/test3/" />
                </rule>

                <rule name="Reverse Proxy to test1" stopProcessing="true">
                    <match url="^test1/*(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Rewrite" url="http://localhost:8093/test1/{R:1}" />
                </rule>
                <rule name="Reverse Proxy to test2" stopProcessing="true">
                    <match url="^test2/*(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Rewrite" url="http://localhost:8093/test2/{R:1}" />
                </rule>
                <rule name="Reverse Proxy to test3" stopProcessing="true">
                    <match url="^test3/*(.*)" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
                    <action type="Rewrite" url="http://localhost:8093/test3/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
0
votes

Try installing "Application Request Routing" extension and configuring it.

https://www.iis.net/downloads/microsoft/application-request-routing