Friday, January 28, 2011

IIS7 URL ReWrite Module: Force to root

We have two sites in IIS7 both on port 80. One is our actual website (MAIN) the other is a maintenance site (MAINTENANCE) that we start (and stop the other one) when we are deploying a new version of MAIN.

When we put MAINTENANCE live, if you browse to one of our subfolders (i.e. http://maintenance/product1) you'll get a 404. I want to use the URL Rewrite module to redirect to the root of the site (http://maintenance/).

I can get this working in a basic manner, but the image and css are not working. In other attempts I have ended up with a continual redirect.

Is this possible?

  • For anyone who arrives here via Google, I managed to get it to work with the following rule:

    <rewrite>
    <rules>
            <clear />
            <rule name="Force HTTP" stopProcessing="true">
                <match url="(.*)" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{HTTPS}" pattern="on" />
                </conditions>
                <action type="Redirect" url="/{R:1}" redirectType="Temporary" />
            </rule>
            <rule name="Allow Local Resources" stopProcessing="true">
                <match url=".*" />
                <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
                    <add input="{REQUEST_FILENAME}" pattern="SiteMaintenance.png" />
                    <add input="{REQUEST_FILENAME}" pattern="Stylesheet.css" />
                </conditions>
                <action type="None" />
            </rule>
            <rule name="Check Is Root" stopProcessing="true">
                <match url="^.+$" negate="false" />
                <conditions logicalGrouping="MatchAny" trackAllCaptures="false" />
                <action type="Redirect" url="/" appendQueryString="false" redirectType="Temporary" />
            </rule>
    </rules>
    </rewrite>
    

    No idea if this is the best way, but it worked for me.

    :)

0 comments:

Post a Comment