Chat with us, powered by LiveChat

External address pointing to internal server on a different port | URL Rewrite | No Server Farm

Thursday, 15 September 2016

External address pointing to internal server on a different port | URL Rewrite | No Server Farm

This post is related to URL Rewrite on an IIS server which does not have server farms enabled.  I will create another post to cover the same process with Server Farms enabled as it’s a completely different requirement.  Click here to find out more about Server Farms.

Recently a client has asked us to look into URL Rewrite and Application Request Routing to see if we’re able to achieve the following:

  • Access externally facing web address: subdomain.domain.com/webapp on port 80
  • ARR and URL Rewrite then forwards this to <servername>.domain.local on port 8080
The easiest way to show you how this was achieved would be by just showing you the web.config file.  This is the file that’s located under the Default Web Site which defines all the settings with IIS that we will be changing.  You will simply have to change all the items I’ve labelled in bold and underlined, to suit your setup, and then you should be good to go.
I will also explain each bold/underlined item under this web.config file so you know what you’re changing.

 

<?xml version=”1.0″ encoding=”UTF-8″?>
<configuration>
    <system.webServer>
        <rewrite>
    <rules>
        <rule name=”Reverse Proxy to webapp” stopProcessing=”true”>
            <match url=”webapp” />
            <action type=”Rewrite” url=”http://ca.atlab.local:8080” />
        </rule>
    </rules>
            <outboundRules>
                <rule name=”Outbound Rule – URL Rewrite” preCondition=”IsHTML”>
                    <match filterByTags=”A” pattern=”^/(.*)” />
                    <conditions>
                        <add input=”{URL}” pattern=”webapp” />
                    </conditions>
                    <action type=”Rewrite” value=”/{C:0}/{R:0}” />
                </rule>
                <preConditions>
                    <preCondition name=”IsHTML”>
                        <add input=”{RESPONSE_CONTENT_TYPE}” pattern=”^text/html” />
                    </preCondition>
                </preConditions>
            </outboundRules>
        </rewrite>
    </system.webServer>
</configuration>
  • WEBAPP
    • Match URL=”webapp”
      • This is the section where it looks for the trigger to run this rule.  If you don’t have “/webapp”, then it won’t rewrite your URL and redirect you to the new location
  • http://ca.atlab.local:8080
    • action type=”Rewrite” url=”http://ca.atlab.local:8080
      • Once you have triggered the rewrite by adding “/webapp” to your URL address, this is the location that it will forward the traffic to essentially.  In this case it’s an internal server, but it can be any location (external or internal) on any port.
  • WEBAPP
    • <add input=”{URL}” pattern=”webapp” />
      • This is the ARR section of the config.  This should be named the same as the first section.