« Previous Next »

Thread: outbound rules URL rewriting HTTP_HOST

Last post 09-01-2009 12:19 PM by ruslany. 6 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (7 items)

Sort Posts:

  • 08-31-2009, 3:04 AM

    • ISO3200
    • Not Ranked
    • Joined on 08-31-2009, 6:49 AM
    • Posts 8

    outbound rules URL rewriting HTTP_HOST

    I'm running a reverse proxy using ARR and URL rewrite v2 beta.  So far, the reverse proxy is working fine.  I'm trying to setup outbound rules to inspect the HTML response to rewrite any href or src attributes in <a> tags.  So far, any request to http://www.proxyserver.com/foo.aspx is routed and rewritten properly to http://www.targetserver.com/foo.aspx.  Great!

    But somewhere in the html of foo.aspx there is an <a href="http://www.targetserver.com/bar.aspx">Go to bar</a> that I want to be rewritten in an outbound rule as http://www.proxyserver.com/bar.aspx.  Is this possible?  I've read http://learn.iis.net/page.aspx/465/url-rewrite-module-configuration-reference/ and am finding myself stuck on trying to get the pattern to match on host and not path.

    Any help on this is much appreciated

    Here's my rules so far:

    <rewrite>
                <rules>
    <rule name="Reverse Proxy to target" stopProcessing="true">
                <match url="^(.*)" />
                <action type="Rewrite" url="https://www.targetserver.com/{R:1}" />
            </rule>

                </rules>
                <outboundRules>
                    <rule name="Rewrite URLs in markup" patternSyntax="ECMAScript" stopProcessing="false" preCondition="HTML Only">
                        <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" customTags="" pattern="targetserver.com" ignoreCase="true" negate="false" />
                        <conditions logicalGrouping="MatchAny" trackAllCaptures="false" />
                        <action type="Rewrite" value="proxyserver.com" />

                    </rule>

                    <preConditions>

                        <preCondition name="HTML Only" logicalGrouping="MatchAny" patternSyntax="ECMAScript">
                            <add input="{HTTP_CONTENT_TYPE}" pattern="^text/html" />
                        </preCondition>

                    </preConditions>

                </outboundRules>
            </rewrite>

  • 08-31-2009, 1:31 PM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 3:38 PM
    • Redmond, WA
    • Posts 661

    Re: outbound rules URL rewriting HTTP_HOST

    Try changing the outbound rule as below:

    <rule name="Rewrite URLs in markup" preCondition="HTML Only">
       <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="http://www\.targetserver\.com(.*)" />
      <action type="Rewrite" value="http://www.proxyserver.com{R:1}" />
    </rule>

     

    http://ruslany.net
  • 08-31-2009, 2:33 PM In reply to

    • ISO3200
    • Not Ranked
    • Joined on 08-31-2009, 6:49 AM
    • Posts 8

    Re: outbound rules URL rewriting HTTP_HOST

    Thanks Ruslan!  It works...but....

    I had to exclude this URL from our HTTPModule that performs GZipping (Ben Lowery's module).  Long story: We were running on IIS5 so we decided to do GZip using ASP.NET.

    Do you know if there's an issue inspecting markup that was previously GZipped by the target server?  (I'm not sure if it matters who does the GZipping - web server or httpmodule).

    .  

  • 08-31-2009, 5:06 PM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 3:38 PM
    • Redmond, WA
    • Posts 661

    Re: outbound rules URL rewriting HTTP_HOST

    If the markup comes to the proxy server in compressed form from the target server, then I do not think it is possible to rewrite it.

    http://ruslany.net
  • 08-31-2009, 5:35 PM In reply to

    • ISO3200
    • Not Ranked
    • Joined on 08-31-2009, 6:49 AM
    • Posts 8

    Re: outbound rules URL rewriting HTTP_HOST

    Ok.  Thanks very much.  Your previous post I'll "mark as answer" but it wasn't the answer I was hoping for :(  Hopefully this'll be possible in the future.


  • 09-01-2009, 2:12 AM In reply to

    • ISO3200
    • Not Ranked
    • Joined on 08-31-2009, 6:49 AM
    • Posts 8

    Re: outbound rules URL rewriting HTTP_HOST

    One workaround to receive uncompressed (i.e. non-GZipped) response from the server is to clear the Accept-Encoding HTTP header (default values are "gzip,deflate").  This can be added in the inbound rule markup.  Of course, this is less than optimal but will allow rewriting markup in the outbound rule.

    <rule name="Reverse Proxy to target" stopProcessing="true">
                <match url="^(.*)" />
                <action type="Rewrite" url="https://www.targetserver.com/{R:1}" />

    <serverVariables>       
        <set name="HTTP_Accept-Encoding" value="" />
        </serverVariables>
            </rule>



     

  • 09-01-2009, 12:19 PM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 3:38 PM
    • Redmond, WA
    • Posts 661

    Re: outbound rules URL rewriting HTTP_HOST

    Yes, that's a good workaround. You can even be more selective and only remove Accept-Encoding header from requests where you expect to do outbound rewriting. For example if you never going to rewrite css and js files, then you can change the pattern to be

    <match url="(.+\.(?:js|css))$" negate="true" />

    http://ruslany.net
Page 1 of 1 (7 items)
Microsoft Communities