0

Is there a way to capture part of the url in an outbound rule to use as value for the re-write?

Right now, I'm using a precondition, where I have an input with a pattern against the {REQUEST_URI}. I'd like to use a capture group from the request URI in the outbound rule that uses this precondition. I tried {C:1} but that didn't work.

Precondition:

<preCondition name="Html Response" logicalGrouping="MatchAll">
    <add input="{REQUEST_URI}" pattern="myapp(.*)" />
    <add input="{RESPONSE_CONTENT_TYPE}" pattern="^(text/html)" />
</preCondition>

Outbound rule:

<rule name="ResponseRewriteRelative" preCondition="Html Response" stopProcessing="true">
    <match filterByTags="A, Link" pattern="^/(.*)" />
    <action type="Rewrite" value="{C:1}/{R:1}" />
</rule>

where {C:1} would be the capture group from precondition "myapp(.*)"

So, it'd go from http://myapp40.com to rewrite links in the response to something similar to 40/originalrelativelink

Thanks!

aggFTW
  • 426
  • 3
  • 12

1 Answers1

2

I just found out that you can add a condition to the outbound rule per se. Just answering here in case there's any other clueless person struggling with the rewrite rules :)

Rule would look something like:

<rule name="ResponseRewriteRelative" preCondition="Html Response" stopProcessing="true">
    <match filterByTags="A, Link" pattern="^/(.*)" />
    <action type="Rewrite" value="{C:1}/{R:1}" />
    <conditions>
        <add input="{REQUEST_URI}" pattern="myapp(.*)" />
    </conditions>
</rule>
aggFTW
  • 426
  • 3
  • 12
  • just a request. i am new in iis rewrite rule. so i have some issue and posted here. would you please have a look at my issue. url is https://stackoverflow.com/questions/47474674/iis-rewrite-rule-change-my-current-aspx-page-hyperlink-href-wrong-way – Thomas Nov 26 '17 at 13:04