IIS URL Rewrite – Directing All Traffic to the Site Root

I recently had a need to redirect all of a web site’s incoming traffic to that site’s home page. 

All of the site’s content had been migrated to a new site, and so now the old site simply needed to let users know what had happened and give them a link to the new site. 

A simple page with some text, a link, and an image was created to replace the home page.  Then, the following IIS URL Rewrite rules were added to direct all incoming traffic to the new home page:

<rewrite>
    <rules>
        <rule name="Allow Local Resources" stopProcessing="true">
            <match url=".*" />
            <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
                <add input="{REQUEST_FILENAME}" pattern="image.jpg" />
            </conditions>
            <action type="None" />
        </rule>
        <rule name="RedirectAllToSiteRoot" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
            <match url="^.+$" negate="false" />
            <action type="Redirect" url="/" appendQueryString="false" />
            <conditions logicalGrouping="MatchAny" trackAllCaptures="false" />
        </rule>
    </rules>
</rewrite>

These settings were added to the “system.webServer” section of the web.config.  The first rule allows the image to be served (without redirecting), and the second directs all incoming traffic to the site root.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: