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

Want to thank me?

If I've helped you out and you want to thank me, why not buy me a coffee?

About the author

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.

Related Posts

How to fix corrupt accented characters in Excel for a C# export as CSV

This post will help you fix the issue where you csv export has corrupt characters when opening it in…

Read Post

How to create a dynamic image from multiple images using ImageProcessor

This post shows you how I created a handler to create dynamic header images for my umbraco website u…

Read Post

How to send Slack messages programmatically using C#

In this post I show you how you can send Slack messages programmatically using C#

Read Post

How to fix the SVG 404 error when using Umbraco and Azure Blob Storage

In this post I show you how to solve the SVG 404 error when working with Umbraco and Azure Blob Stor…

Read Post