Enabling response compression when using IIS URL Rewrite with cross-application proxy setup

I have configured IIS to act as a proxy server that forwards requests to an internal backend application. The proxy functionality works fine but I noticed that responses coming back from the backend are not getting compressed before being sent to the client browser.

Here is my current configuration:

  • Internal backend application running at https://backend.internal (not publicly accessible)
  • Public IIS 7.5 server at https://public.example.com that handles both the main website and proxy requests
  • Need to forward requests from https://public.example.com/service/PATH to https://backend.internal/PATH

I am using URL Rewrite 2.0 and Application Request Routing extensions. Here is the relevant web.config:

<system.webServer>
  <rewrite>
    <rules>
      <rule name="Forward to internal service" stopProcessing="true">
        <match url="^service/(.*)" />
        <conditions>
          <add input="{CACHE_URL}" pattern="^(https?)://" />
        </conditions>
        <action type="Rewrite" url="{C:1}://backend.internal/{R:1}" />
        <serverVariables>
          <set name="HTTP_ACCEPT_ENCODING" value="" />
        </serverVariables>
      </rule>
    </rules>
    <outboundRules>
      <rule name="FixAbsoluteUrls" preCondition="IsHtmlContent">
        <match filterByTags="A, Form, Link, Script" pattern="^http(s)?://backend.internal/(.*)" />
        <action type="Rewrite" value="/service/{R:2}" />
      </rule>
      <rule name="FixRedirects" preCondition="IsHtmlContent">
        <match serverVariable="RESPONSE_LOCATION" pattern="^http(s)?://backend.internal/(.*)" />
        <action type="Rewrite" value="/service/{R:2}" />
      </rule>
      <preConditions>
        <preCondition name="IsHtmlContent">
          <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
        </preCondition>
      </preConditions>
    </outboundRules>
  </rewrite>
  <urlCompression dynamicCompressionBeforeCache="false" />
</system.webServer>

The issue is that I must clear the HTTP_ACCEPT_ENCODING header to avoid this error: “HTTP Error 500.52 - URL Rewrite Module Error. Outbound rewrite rules cannot be applied when the content of the HTTP response is encoded (gzip).”

I have tried setting dynamicCompressionBeforeCache="false" and verified the module order in IIS but compression still does not work when proxying to a different application. Simple URL rewrites within the same app work fine with compression.

Is there a way to enable gzip compression for responses that come from the proxied backend server?

Interesting setup! Have you tried moving the compression after the backend response? Maybe use a custom handler or check if ARR has built-in compression for proxy scenarios. What ARR version are you running?

The problem is that IIS decompresses responses to apply outbound rewrite rules, which breaks your compression setup. Here’s what worked for me: Set up your backend to serve uncompressed responses when it detects proxy requests, then let IIS handle compression on the proxy server. Or you can make your outbound rules more selective - only target response types that actually need URL rewriting and let everything else stay compressed. I fixed a similar issue by building custom response filtering that transformed URLs without decompressing everything, but that meant extra dev work on the backend.

had the same prob. try skipping the whole HTTP_ACCEPT_ENCODING clearin, and set dynamicCompressionBeforeCache=“true” instead. also, make sure ur backend aint compressing responses already, that could mess with IIS compression.