I'm trying to create a reverse proxy which will rewrite all requests to a particular URL to another server inside the DMZ. I got the setup and configuration working based on this article
https://learn.iis.net/page.aspx/659/reverse-proxy-with-url-rewrite-v2-and-application-request-routing
So my basic setup is like this –
Base URL which should trigger rewrite – http://MySite/Custom?Data=123
Proxy URL – http://MyProxyServer/Service?Data=123
My problem is with the two BOLD keywords above! I just cannot seem to successfully rewrite all requests to new URL.
Explaining in detail –
When i use the following rule –
<rule name="ReverseProxy" stopProcessing="true">
<match url="Custom/(.*)" />
<action type="Rewrite" url="http://MyProxyServer/Service{R:1}" />
</rule>
I get an 404 error saying http://MySite/Service
not found!
Tracing using failed req logs, i can see the rules working perfectly (new url is created correctly) but eventually the request ends with 404 error.
Thing is, if i slightly tweak the rule, everything works fine.
Following rule works –
<rule name="ReverseProxy" stopProcessing="true">
<match url="Service/(.*)" />
<action type="Rewrite" url="http://MyProxyServer/Service{R:1}" />
</rule>
But i have to change my base url to http://MySite/Service?Data=123
from http://MySite/Custom?Data=123
So is there a limitation with reverse proxy implementation in IIS 7 where we have to match the sub directory/virtual directory names between source and proxy or are my rules inadequate?
Best Answer
There is an undocumented issue with ARR / rewrite, where it cannot map subfolders. I am adding this for my reference and hoping it helps others
A workaround I have tried that seems to be effective, is to create a folder inside your source web application, add a web.config inside that folder with the rules pointing to the destination web application:
Also added instructions from https://blogs.msdn.microsoft.com/friis/2016/08/25/iis-with-url-rewrite-as-a-reverse-proxy-part-2-dealing-with-500-52-status-codes/ around GZIP