Last updated
Last updated
Since the release of Umbraco v9 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 , which needs to be added to your project startup code first.
Make sure to check the official documentation for more information about when you should or should not use the URL Rewriting Middleware.
To use rewrites with Umbraco v9+ you have to register the middleware in your Program.cs
by using the extension method and then configure the rewrite options.
Create an IISUrlRewrite.xml
file in the root of your project (next to your Program.cs
file) containing:
In your csproj file add the XML file to a new item group and set CopyToOutputDirectory
to Always
:
RewriteOptions
has a number of "shortcut" methods to implement commonly used rewrites including:
AddRedirectToNonWww()
AddRedirectToWww()
AddRedirectToNonWwwPermanent()
AddRedirectToWwwPermanent()
AddRedirectToHttps()
If you are looking for additional inspiration or examples for creating IIS Rewrite rules, these external resources are a great starting point:
The following rule removes any trailing slashes from the URL.
The following rule ensures your site only runs on HTTPS:
The following rule redirects traffic from non-www to www (excluding the Umbraco Cloud project hostname):
The following rule redirects .aspx
URLs to their extensionless counterparts.
An example configuration to help ensure your custom rules integrate properly:
In the Program.cs
file you can add the URL Rewriting Middleware before the call to app.UseUmbraco()
and use to add the rewrite rules from the XML file:
For more details and other examples, take a look at the and documentation.
A great site showing 10 handy IIS Rewrite rules:
Another site showing some handy examples of IIS Rewrite rules:
If you needed to a lot of static rewrites using rewrite maps:
Ensure Umbraco does not add a trailing slash by setting AddTrailingSlash
to false
in your .
If you use Umbraco Cloud, check the article.