Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Error 500.52 - URL Rewrite Module Error.

I am trying to setup a reverse proxy with IIS 7.5. I want an incoming request that matches a certain URL pattern to be served by Tomcat. I have used the tutorial here to configure it.

http://www.iis.net/learn/extensions/url-rewrite-module/reverse-proxy-with-url-rewrite-v2-and-application-request-routing

My settings are as below:

<rewrite>
        <rules>                
            <rule name="ReverseProxyInboundRule1" stopProcessing="true">
                <match url=".*/(Locations|FacetedSearch|LocationPage)/.*" />
                <action type="Rewrite" url="http://search.xxx.com/{R:1}" />
                 <serverVariables>
                    <set name="HTTP_ACCEPT_ENCODING" value="" replace="true" /> 
                </serverVariables>
            </rule>
        </rules>
        <outboundRules>
            <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
                <match filterByTags="A, Form, Img" pattern="^http(s)?://search.xxx.com/(.*)" />
                <action type="Rewrite" value="http{R:1}://dev.xxx.com/{R:2}" />
            </rule>
            <preConditions>
                <preCondition name="ResponseIsHtml1">
                    <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                </preCondition>
            </preConditions>
        </outboundRules>
    </rewrite>
    <tracing>

HTTP Error 500.52 - URL Rewrite Module Error. Outbound rewrite rules cannot be applied when the content of the HTTP response is encoded ("deflate").

like image 650
Chirdeep Tomar Avatar asked Jan 08 '13 12:01

Chirdeep Tomar


1 Answers

I just hit this issue as well, and I found this solution helpful: https://www.saotn.org/iis-outbound-rules-with-gzip-compression/

Basically, on inbound requests the HTTP_ACCEPT_ENCODING header gets stashed into a temporary header, and then gets restored back on the outbound rewrite rule.

In the case the link goes dead, here's the steps:

  1. Through the IIS Manager GUI on the server node in the left pane, navigate to URL Rewrite
  2. Click View Server Variables in the right pane
  3. Add two Allowed Server Variables:
HTTP_ACCEPT_ENCODING
HTTP_X_ORIGINAL_ACCEPT_ENCODING
  1. Back in URL Rewrite options for the Server, click on View Preconditions in the right pane. Add a new precondition (I named it NeedsRestoringAcceptEncoding)
  2. Set the Condition Input to {HTTP_X_ORIGINAL_ACCEPT_ENCODING} and the Pattern to ".+" (no quotes).
  3. On the inbound rewrite rule that is causing the error, add the following to Server Variables (you'll find it underneath the Conditions section):
Server Variable Name: HTTP_X_ORIGINAL_ACCEPT_ENCODING
Value: {HTTP_ACCEPT_ENCODING}

Server Variable Name: HTTP_ACCEPT_ENCODING
Value: ""
  1. On the outbound rewrite rule, add the precondition created from steps 4-5 to the Precondition section of the rule (it should be populated in the drop-down box)

In the case that you only need this functionality on a single site, you can add the precondition at the site-level instead of the server-level.

like image 70
techfooninja Avatar answered Sep 29 '22 00:09

techfooninja