I have a asp.net website hosted on iis 7.5. I am trying to use iis rewriter module for reverse proxy. I have implemented the following code in web.config file. The code is working for 1 website news.mysite.co.uk but not working for blog.mysite.co.uk. It's looks like i have not implemented outbond rule correctly.
<rule name="Route the requests for newa" stopProcessing="true">
<match url="^news/(.*)" />
<conditions>
<add input="{CACHE_URL}" pattern="^(https?)://" />
</conditions>
<action type="Rewrite" url="{C:1}://news.mysite.co.uk/{R:1}" />
<serverVariables>
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
</rule>
<rule name="Route the requests for blog" stopProcessing="true">
<match url="^blog/(.*)" />
<conditions>
<add input="{CACHE_URL}" pattern="^(https?)://" />
</conditions>
<action type="Rewrite" url="{C:1}://blog.mysite.co.uk/{R:1}" />
<serverVariables>
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
</rule>
</rules>
<outboundRules>
<rule name="Add application prefix 2" preCondition="ResponseIsHtml2">
<match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^/(.*)" />
<conditions>
<add input="{URL}" pattern="^/.*" />
</conditions>
<action type="Rewrite" value="/blog/{R:1}" />
</rule>
<rule name="ReverseProxyOutboundRule2" preCondition="ResponseIsHtml2">
<match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^http(s)?://blog.mysite.co.uk/(.*)" />
<action type="Rewrite" value="/blog/{R:2}" />
</rule>
<rule name="Add application prefix" preCondition="ResponseIsHtml1">
<match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^/(.*)" />
<conditions>
<add input="{URL}" pattern="^/.*" />
</conditions>
<action type="Rewrite" value="/news/{R:1}" />
</rule>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
<match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^http(s)?://news.mysite.co.uk/(.*)" />
<action type="Rewrite" value="/news/{R:2}" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
<preCondition name="ResponseIsHtml2">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
Here is the final working code.
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="^news/(.*)" />
<action type="Rewrite" url="http://news.mysite.co.uk/{R:1}" />
<serverVariables>
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
</rule>
<rule name="ReverseProxyInboundRule2" stopProcessing="true">
<match url="^blog/(.*)" />
<action type="Rewrite" url="http://blog.mysite.co.uk/{R:1}" />
<serverVariables>
<set name="HTTP_ACCEPT_ENCODING" value="" />
</serverVariables>
</rule>
</rules>
<outboundRules>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml2">
<match filterByTags="A, Img" pattern="^/(.*)" />
<conditions>
<add input="{URL}" pattern="^/(news|blog)/.*" />
</conditions>
<action type="Rewrite" value="/{C:1}/{R:1}" />
</rule>
<rule name="ReverseProxyOutboundRule2" preCondition="ResponseIsHtml2">
<match filterByTags="A, Form, Img" pattern="^http(s)?://news.mysite.co.uk/(.*)" />
<action type="Rewrite" value="/news/{R:2}" />
</rule>
<rule name="ReverseProxyOutboundRule4" preCondition="ResponseIsHtml2">
<match filterByTags="A, Form, Img" pattern="^http(s)?://blog.mysite.co.uk/(.*)" />
<action type="Rewrite" value="/blog/{R:2}" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml2">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
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.