URL Rewrites in Umbraco

With the release of Umbraco 9 and the change of the underlying web framework that is decoupled from the webserver, the way that you configure rewrites has changed as well.
Instead of the URL Rewriting extension in IIS you can use the URL Rewriting Middleware in ASP.NET Core, which needs to be added to your project startup code first.
If you are running Umbraco 9 on IIS you can still add a web.config file to configure IIS features such as URL rewrites.

When to use the URL Rewriting Middleware

Make sure to check the official URL Rewriting Middleware in ASP.NET Core documentation for more information about when you should or should not use the URL Rewriting Middleware.

Using the URL Rewriting Middleware

To use rewrites with Umbraco 9 you have to register the middleware in your Startup.cs by using the UseRewriter extension method and then configure the rewrite options.


  • Create an IISUrlRewrite.xml file in the root of your project (next to your Startup.cs file) containing:
<?xml version="1.0" encoding="utf-8" ?>
<rule name="Redirect to preferred domain" stopProcessing="true">
<match url=".*" />
<add input="{HTTP_HOST}" pattern="\.umbraco\.io$" />
<add input="{REQUEST_URI}" pattern="^/App_Plugins/" negate="true" />
<add input="{REQUEST_URI}" pattern="^/umbraco" negate="true" />
<action type="Redirect" url="{R:0}" />
  • In the Startup.cs file you can add the URL Rewriting Middleware just before the call to app.UseUmbraco() and use AddIISUrlRewrite) to add the rewrite rules from the XML file:
using Microsoft.AspNetCore.Rewrite;
app.UseRewriter(new RewriteOptions().AddIISUrlRewrite(env.ContentRootFileProvider, "IISUrlRewrite.xml"));
  • In your csproj file add the XML file to a new item group and set CopyToOutputDirectory to Always:
<Content Include="IISUrlRewrite.xml">
On Umbraco Cloud the item group needs to be set to <CopyToPublishDirectory>Always</CopyToPublishDirectory> for the file to be published to your deployed site.

Examples of rewrite rules

For example, to always remove a trailing slash from the URL (make sure Umbraco doesn't add a trailing slash to all generated URLs by setting AddTrailingSlash to false in your RequestHandler settings):
<rule name="Remove trailing slash" stopProcessing="true">
<match url="(.*)/+$" />
<add input="{REQUEST_URI}" pattern="^/umbraco" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<action type="Redirect" url="{R:1}" />
Another example would be to enforce HTTPS only on your site:
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url=".*" />
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{HTTP_HOST}" pattern="^localhost(:[0-9]+)?$" negate="true" />
<action type="Redirect" url="https://{HTTP_HOST}/{R:0}" />
Another example would be to redirect from non-www to www (except for the Umbraco Cloud project hostname):
<rule name="Redirect to www prefix" stopProcessing="true">
<match url=".*" />
<add input="{HTTP_HOST}" pattern="^www\." negate="true" />
<add input="{HTTP_HOST}" pattern="^localhost(:[0-9]+)?$" negate="true" />
<add input="{HTTP_HOST}" pattern="\.umbraco\.io$" negate="true" />
<action type="Redirect" url="https://www.{HTTP_HOST}/{R:0}" />
Adding the www redirect rule requires a <add input="{HTTP_HOST}" pattern=".**" negate="true" ignoreCase="true" /> condition to be added in order for Umbraco Cloud to function correctly.
This step is required for the deployment service and the content transfer between environments to continue to function.