简体   繁体   中英

IIS rewrite rule not matching — setting up reverse proxy

This seems to be like the simplest of thing which I am unable to resolve.

I want to rewrite URL if it contains the string extFlow , to a different host.

http://site1/extFlow/Testsvc/GetData/?val=1

to

http://site2/extFlow/Testsvc/GetData/?val=1

I have tried all rules eg:

  <rules>
    <rule name="Reverse Proxy to external" stopProcessing="true">
      <match url="extFlow/(.*)" />
      <action type="Rewrite" url="http://site2/{R:1}" />
    </rule>
  </rules>

If I just match with (.*) then the rewrite happens.

I am not able to match even with * match url="extFlow"

What am I missing?

Based on your statement "Yes for testing purpose I have both sites on same machine, but on a different port", I think that's what is breaking your rule. Let me disintegrate and explain it.

  • Observe how you have "extFlow" in both your URL's.

  • Let's assume a request came in for
    " http://site1/extFlow/Testsvc/GetData/?val=1 ". The URL rewrite rule
    is hit and its rewrites it to
    " http://site2/extFlow/Testsvc/GetData/?val=1 ".

  • Since this new URL also hits the same machine and even it has
    "extFlow" in it, the rule will be triggered once again and again and again.

  • So indirectly you are triggering an indefinite loop here.

Let me know if you have any questions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM