Maharshi
Maharshi

Reputation: 1198

Regex does not work for {URL} in the URL rewrite in IIS

Using URL rewrite in the IIS on windows 10.
I want to check specific url in the IIS. Below is the condition I need to check.

  1. www.mtl173 or http://www.mtl173 or http://www.mtl173/ or mtl173/
    Above all should be valid and should redirect to the given path.

I have checked {URL} so far as following.

<rule name="RuleForSite1" stopProcessing="true">
        <match url="(.*)" ignoreCase="false" />
        <conditions>
            <add input="{URL}" pattern="^(http\:\/\/)?(www\.)?mtl173(\/)?$" />
        </conditions>
        <action type="Redirect" url="www.mtl173/app1/" />
    </rule>

Note: when I test all the URLs in the IIS, all test passed but when I run the same URL from the browser, it shows me the default IIS page and does not redirect me to the app1/.

However, the above does not work and does not redirect the URL to the given path. Any remediations for the issue I am facing?

Expected result:
When I enter any of the following URL, it should redirect me to the /app1.

  1. www.mtl173
  2. http://www.mtl173
  3. http://www.mtl173/
  4. mtl173/

Upvotes: 0

Views: 91

Answers (1)

Jalpa Panchal
Jalpa Panchal

Reputation: 12749

You can use below url rewrite rule.

  <rule name="RuleForSite1" stopProcessing="true">
    <match url="(.*)" ignoreCase="false" />
    <conditions>
                    <add input="{HTTP_HOST}" pattern="^www.mtl173|mtl173$" />
                    <add input="{REQUEST_URI}" pattern="app1" negate="true" />
    </conditions>
    <action type="Redirect" url="http://www.mtl173/app1/" />
</rule>

enter image description here

enter image description here

You can learn about server variable from below links: IIS Server Variables

Upvotes: 1

Related Questions