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:

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

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.