URL Rewrite And A Sorry Server

by Vaughn Anderson 2. August 2011 10:00

We have our load balancers configured if all the servers in a VIP fail, then they redirect all traffic to a sorry server.  This seemed easy enough, but then when we tested it, we found some weird results.  For example, if someone goes to http://www.site.com and that request hits the sorry server, things work without any issues.  The sorry server will display the under maintenance page since the user was trying to access the default document on the web site.

What if a user has a login page bookmarked and it looks something like this – https://site.com/login.aspx?ID=725?  That request will not be captured by the default document.  Initially, I thought I could just make my “Under Maintenance” page my default 404 error page displaying the under maintenance banner, but that’s bad hosting.  The proper response for something that is temporarily unavailable is a 307.  Therefore, I needed a way to redirect all traffic to the maintenance page, but give a 307 response.  Plus, it must be a lightweight solution since the sorry server is a VM that does not have that much processing power.  URL Rewrite to the rescue.

Open URL Rewrite in IIS and create a new Blank Rule.  I called mine “Redirect all.”  Here’s a picture of my configuration and the code if you want to add it directly to your web.config.  Then I will explain why I configured it this way.

image

Web.config code:

<rules>
    <rule name="Redirect all" enabled="true" stopProcessing="true">
        <match url="(.*)" negate="false" />
        <action type="Redirect" url="/index.htm" redirectType="Temporary" />
        <conditions>
            <add input="{REQUEST_FILENAME}" pattern="index\.htm" negate="true" />
        </conditions>
    </rule>

So let’s break this down section by section.

  • In the Match URL area, I want to capture all traffic, hence the (.*) pattern.
  • For the Conditions, I wanted anything that did not match the default document of index.htm to flag a condition. This is because the only page that works properly is the default document.
  • I didn’t have any server variables.
  • For the Action, I wanted to redirect all traffic caught in the “Conditions” section and redirect it to the default document.  Since I have many different URLs feeding to this rule, I just left the generic relative path of /index.htm.

Tags:

IIS | URL Rewrite

Add comment




biuquote
  • Comment
  • Preview
Loading






About the author

Just a guy trying to record what he does in IIS and Hyper-V so others might benefit.

Month List