This post teaches you how to set rewrite rules for your umbraco site. You may want to force your site to go to a secure url or force it to go to a url with www. at the start.

If you are looking for the new way to do it, using the ASP.NET rewrites have a look at this post.

To add these rules, you need to go to the file /config/UrlRewriting.config

<?xml version="1.0" encoding="utf-8"?>
<urlrewritingnet xmlns="http://www.urlrewriting.net/schemas/config/2006/07">
<rewrites>
<!-- Use this rule to redirect a url without www at the front to one with www at the front. - From http://codeshare.co.uk to http://www.codeshare.co.uk -->
<add name="NoWWW" virtualUrl="^http\://codeshare\.co\.uk/(.*)" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="http://www.codeshare.co.uk/$1" redirect="Domain" redirectMode="Permanent" ignoreCase="true" />

<!-- Use this rule to redirect a secure url without www to a secure url with www. at the front. - From http://codeshare.co.uk/ to https://www.codeshare.co.uk/ -->
<add name="NoWWWS" virtualUrl="^https\://codeshare\.co\.uk/(.*)" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="https://www.codeshare.co.uk/$1" redirect="Domain" redirectMode="Permanent" ignoreCase="true" />

<!-- Use this rule to redirect a non-secure url to a secure one with www at the front. - From http://codeshare.co.uk/ to https://www.codeshare.co.uk/ -->
<add name="Secure" virtualUrl="^http\://(.*)" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="https://$1" redirect="Domain" redirectMode="Permanent" ignoreCase="true" />

<!-- Use this rule to redirect the xml sitemap path. - From http://www.codeshare.co.uk/sitemap.xml to https://www.codeshare.co.uk/xmlsitemap -->
<add name="sitemapxml" virtualUrl="~/sitemap\.xml" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="/xmlsitemap" redirect="Domain" redirectMode="Permanent" ignoreCase="true" />
</rewrites>
</urlrewritingnet>

You will find the last rule useful when trying to implement the code in my other post XML Sitemap in Umbraco

I hope you found this post useful, feel free to share with others.

Want to learn more about Umbraco?

Follow along with this video to get you started with Umbraco

Paul Seal

Umbraco MVP and .NET Web Developer from Derby (UK) who specialises in building Content Management System (CMS) websites using MVC with Umbraco as a framework. Paul is passionate about web development and programming as a whole. Apart from when he's with his wife and son, if he's not writing code, he's thinking about it or listening to a podcast about it.

Proudly sponsored by

Moriyama

  • Moriyama build, support and deploy Umbraco, Azure and ASP.NET websites and applications.
AppVeyor

  • CI/CD service for Windows, Linux and macOS
  • Build, test, deploy your apps faster, on any platform.
elmah.io

  • elmah.io is the easy error logging and uptime monitoring service for .NET.
  • Take back control of your errors with support for all .NET web and logging frameworks.
uSync Complete

  • uSync.Complete gives you all the uSync packages, allowing you to completely control how your Umbraco settings, content and media is stored, transferred and managed across all your Umbraco Installations.
uSkinned

  • More than a theme for Umbraco CMS, take full control of your content and design with a feature-rich, award-nominated & content editor focused website platform.
UmbHost

  • Affordable, Geo-Redundant, Umbraco hosting which gives back to the community by sponsoring an Umbraco Open Source Developer with each hosting package sold.