IIS Url Rewrite ARR issue

2019-09-08 11:26发布

问题:

I configured IIS as a reverse proxy using Url Rewrite module and ARR 3. I have a public domain which redirect to my application on localhost. It's working fine excepted when the application redirect to another host. ie: redirecting to "https://www.google.com/search?q=url+rewrite+iis+arr+3" My browser shows "http://localhost/search?q=url+rewrite+iis+arr+3" which fails

The hosted application is using Asp Net Mvc with framework.net 4.5. The application is working with integrated pipeline in IIS application pool configuration.

Using Fiddler, I can see the following trace on redirect :

HTTP/1.1 302 Found
Cache-Control: private
Content-Length: 350
Content-Type: text/html; charset=utf-8
Location: http://localhost/search?q=url+rewrite+iis+arr+3
Server: Microsoft-IIS/7.5
X-Powered-By: ARR/3.0
X-Powered-By: ASP.NET
Date: Wed, 02 Nov 2016 16:39:18 GMT

<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="https://www.google.com/search?q=url+rewrite+iis+arr+3">here</a>.</h2>
</body></html>

My IIS config :

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="ReverseProxyInboundRule" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="http://localhost/{R:1}" />
                </rule>
            </rules>
            <outboundRules>
                <rule name="ReverseProxyOutboundRule1" preCondition="IsRedirection" stopProcessing="true">
                    <match filterByTags="A" pattern="^http(.*)" negate="false" />
                    <action type="None" />
                </rule>
                <preConditions>
                    <preCondition name="IsRedirection">
                        <add input="{RESPONSE_STATUS}" pattern="3[0-9][0-9]" />
                    </preCondition>
                </preConditions>
            </outboundRules>
        </rewrite>
    </system.webServer>
</configuration>

回答1:

Thanks to milope on IIS.net forums (don't know if I can post the link) for giving me the following solution:

In the server level Application Request Routing Cache feature, there is a link that reads: Server Proxy Settings or something like that. Check if the Reverse rewrite host in response header is checked in the Proxy Settings. If so, this may be why external link go to localhost.

This worked for me and solved my redirect issue.