3

I have the following rewrite rule on an ASP.Net site to get IIS to act as a reverse proxy:

<rewrite>
    <rules>
        <rule name="AppReverseProxy" enabled="true" stopProcessing="true">
            <match url="([d|u|c]/.*)" />
            <action type="Rewrite" url="http://127.0.0.1:12949/{R:1}" />
        </rule>
    </rules>
</rewrite>

So basically, anything at a path of domain.com/u/* domain.com/d/* or domain.com/c/* will get forwarded to the local server. This works fine, and as a rule I've had no issues until now.

I'm having the local server return a 301 Permanent Redirect with a Location header set to a subdomain like: subdomain.domain.com/somePath. This subdomain points to an entirely different server.

The problem is that IIS is rewriting the Location header to look like domain.com/somePath, it's removing the subdomain completely. I confirmed that its an IIS issue by accessing the site at domain.com:12949 and it redirects properly to the subdomain. How can I stop IIS from re-writing the Location header from the local server?

caesay
  • 16,932
  • 15
  • 95
  • 160

1 Answers1

16

Url rewrite can rewrite headers in responses, but should not do this by default. Since this is not configured in the rewrite rule of the website, most likely the Application Request Routing module is enabled at the server level.

In IIS Manager, Select the current server (not the website), open Application Request Routing, and on the right hand column there will be an option Server Proxy Settings. There you will see "Reverse rewrite host in response headers" option. If that is checked - uncheck it and your problem should be solved.

There are some screenshots of the ARR module windows for reference at this URL: https://learn.microsoft.com/en-gb/archive/blogs/chiranth/application-request-routing-part-2reverse-proxy-and-troubleshooting-arr-urlrewrite-issues enter image description here enter image description here

caesay
  • 16,932
  • 15
  • 95
  • 160
Evk
  • 98,527
  • 8
  • 141
  • 191
  • As you can see, I've posted my config in the question - there is no outgoing rewrite rule, no option to rewrite the response headers has been checked. – caesay Sep 15 '15 at 04:57
  • Application Request Routing option I mean is not related to your config file and is not stored there. Usually when you configure reverse proxy with url rewrite module, IIS asks if you want to install ARR. And if you agree, it will install it AND check "Reverse rewrite host in response headers" in it for you. So you might not even know you use this module. – Evk Sep 15 '15 at 05:58
  • This module is located not even on web site level in IIS, but on server level. This post has screenshots of what I mean - http://blogs.msdn.com/b/chiranth/archive/2014/08/03/application-request-routing-part-2-reverse-proxy-and-troubleshooting-arr-urlrewrite-issues.aspx – Evk Sep 15 '15 at 05:59
  • This is correct, thanks. I've edited the answer to be more clear and awarded the bounty. – caesay Sep 15 '15 at 21:20