We have moved!

You are currently looking at documentation for Umbraco 8 and older versions.
An automated guess is that docs.umbraco.com/umbraco-cms/reference/routing/iisrewriterules/ could be the link to the new documentation for Umbraco 9 and newer versions.

    IIS Rewrite Rules

    If you require static rewrites you should use IIS Rewrite rules. This is an IIS plugin that exists outside of Umbraco but should be installed by the vast majority of hosting providers. There is a significant amount of documentation for doing static rewrites with IIS Rewrite rules. This documentation will list some basic examples with links to some reference sites.

    Enabling the rules

    By default the web.config with Umbraco (7.6+) will contain a commented out section that looks like:

    <!--
    If you wish to use IIS rewrite rules, see the documentation here:
    https://our.umbraco.com/documentation/Reference/Routing/IISRewriteRules
    -->
    <!--
    <rewrite>
      <rules></rules>
    </rewrite>
    -->
    

    If you wish to use the rules, be sure that you have the IIS Rewrite Module installed and uncomment the section. If you don't have the IIS Rewrite module installed, you will get a Yellow Screen Of Death (YSOD).

    Storing rules in an external file

    You can store the rules in an external file if you wish by using this syntax:

    <rewrite>
      <rules configSource="config\IISRewriteRules.config" />
    </rewrite>
    

    and creating a file at ~/Config/IISRewriteRules.config with the content:

    <rules></rules>
    

    Examples

    For example, to always remove trailing slash from the URL:

    <rule name="Remove trailing slash" stopProcessing="true">
      <match url="(.*)/$" />
        <conditions>      
          <add input="{REQUEST_URI}" negate="true" pattern="^/umbraco" />
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        </conditions>
      <action type="Redirect" redirectType="Permanent" url="{R:1}" />
    </rule>
    

    Another example would be to enforce HTTPS only on your site:

    <rule name="HTTP to HTTPS redirect" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
        <add input="{HTTP_HOST}" pattern="localhost" negate="true" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
    </rule>
    

    Another example would be to redirect from non-www to www:

    <rule name="Non WWW to WWW" stopProcessing="true">
      <match url="(.*)" ignoreCase="true" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^google\.com" />
      </conditions>
      <action type="Redirect" url="https://www.google.com/{R:1}" redirectType="Permanent" />
    </rule>