Url Rewrites with Microsoft URL Rewrite Module 2.0 for IIS 7

Common rewriting tasks include redirecting to a naked domain (without the www prefix) or redirecting to https. Using the Microsoft URL Rewrite Module for IIS, your site can implement redirect rules in the web.config.

At the time of writing, the module download was here, failing that, searching for Microsoft URL Rewrite Module 2.0 for IIS 7 should return the correct download

After installing, a new Url Rewrite feature will be available

Default website in IIS7

Rewrites can be entered through the UI, or via the web.config

Edit Url Rewrite Inbound Rule in IIS7

There are plenty of resources available on the web for the authoring the rules. Below are 2 rules I have implemented recently, which use a common pattern

Redirect to https

<system.webServer>
        <rewrite>
            <rules>
                <rule name="Redirect to https" stopProcessing="true">
                    <match url=".*" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
                    </conditions>
                    <action 
                      type="Rewrite" 
                      url="https://{C:2}/{R:0}" 
                      redirectType="Permanent" />
                </rule>
            </rules>
        </rewrite>
</system.webServer>

Redirect to naked

<system.webServer>
    <rewrite>
      <rules>
        <rule name="Redirect to naked" stopProcessing="true">
          <match url=".*" ignoreCase="true" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
          </conditions>
          <action 
            type="Redirect" 
            url="http://{C:2}/{R:0}" 
            redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>