.net – IIS Url Rewrite Not Working – 404 Error

iisnetrewriteurl-rewriting

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.

Best Answer

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

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

Related Topic