'IIS URL Rewrite for sub domains

I am trying to set up a URL Rewrite in IIS, which will take a request that is coming from the root https://www.test.com redirects to https://www.test.com/nfc/ but, not redirect the request when the subdomain is 'app' (e.g. https://app.test.com).

I've configured the IIS rewrite script with following attributes:

Request URL: Matches the Pattern Using: Regular Expression Pattern: ^$ Condition: {HTTP_HOST} Does Not Match the pattern ^app.test.com$ Action Type: Redirect Redirect URL: /nfc/ Redirect Type: 307

Will there be a possibility of a recursive redirect that crashes the request. Here are the IIS settings



Solution 1:[1]

There is a problem with your rule, you can try this rule:

<system.webServer>
  <rewrite>
    <rules>
        <rule name="test" stopProcessing="true">
            <match url="^$" />
               <conditions>
                 <add input="{HTTP_HOST}" pattern="^app.test.com$" negate="true"/>
               </conditions>
            <action type="Redirect" url="/nfc" />
        </rule>
    </rules>
  </rewrite>
</system.webServer>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1