erdomke
erdomke

Reputation: 5245

Prevent IIS Url Rewrite module from modifying HTTP 303/307 responses

I have the follow rewrite rule defined in IIS that I would like to maintain. The problem I am encountering is that when the application behind this rewrite returns an HTTP redirect response (303 or 307) to a host other than itself, the URL rewrite module is changing the host on the Location header of the response. (I have confirmed that the URL Rewrite is at fault since this behavior is not observed when accessing the site directly). IIS is doing this even though I do not have any outbound rules defined. How do I keep IIS rewriting the incoming requests, but prevent it from doing this unconfigured and unintended processing of the outgoing responses?

<rule name="ServiceName Rewrite">
  <match url="^(ServiceName/)?(.*)" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^ServiceName([.]company[.]com)?$" />
  </conditions>
  <action type="Rewrite" url="http://generic.company.com/ServiceName/{R:2}" />
</rule>

Edit:

To clarify, my web application is returning a response of

HTTP 307
Location: http://somesite.company.com/path/to/item

and IIS is unhelpfully changing this to

HTTP 307
Location: http://ServiceName.company.com/path/to/item

Upvotes: 6

Views: 4511

Answers (1)

Mateusz
Mateusz

Reputation: 137

I had the same problem with my redirects.

What worked for me was:

  1. In IIS Manager go to your server
  2. Enter Application Request Routing Cache
  3. In Actions go to Server Proxy Settings
  4. Disable checkbox "Reverse rewrite host in response headers"
  5. Restart your server

Upvotes: 9

Related Questions