0

I want to redirect a particular url to another server. Following is my rewrite rule:

<rewrite>
    <rules>
        <rule name="mydomain" patternSyntax="ECMAScript" stopProcessing="true">
            <match url="(http|https)(://domain1\.)(example\.)(com|net)(/research)(.*)" />
            <action type="Redirect" url="{R1}://{R3}{R4}/domain1research" />                   
        </rule>
    </rules>
</rewrite>

I am expecting that if a user types https://domain1.example.com/research, they should be redirected to https://example.com/domain1research. I've tested the expression with multiple variations on the url (.com, .net and query string) and it matches always. But when I run the website it never gets re-directed to the other page. I've URL rewrites in many web apps and they all work fine. I am not able to put my fingre on what I'm missing here.

I have tried it locally with an entry in hosts file and in a published website (Asp.Net MVC) on Azure but nothing works.

TheVillageIdiot
  • 40,053
  • 20
  • 133
  • 188
  • 1
    Mistake 1 https://blog.lextudio.com/the-very-common-mistakes-when-using-iis-url-rewrite-module-a2ab7e4fee59#:~:text=Mistake%202%3A%20Use%20Rewrite%20When%20Actually%20Redirect%20Is,you%20would%20like%20to%20modify%20it%20a%20bit%2C – Lex Li Aug 04 '20 at 13:58

1 Answers1

0

As per @lex Li's blog post and Microsoft documents, following rewrite works:

<rewrite>
    <rules>
        <rule name="mydomain" patternSyntax="ECMAScript" stopProcessing="true">
            <match url="research" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="true">
                    <add input="{HTTP_HOST}" pattern="(domain1\.)(example\.(com|net)" />
                </conditions>
            <action type="Redirect" url="https://{C:2}/domain1research" />                   
        </rule>
    </rules>
</rewrite>
TheVillageIdiot
  • 40,053
  • 20
  • 133
  • 188