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?

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 animate tree icons in Umbraco v8

This post shows you how you can change the colour and animate tree icons in Umbraco based on a prope…

Read Post

How to solve the error assets file project.assets.json not found in Visual Studio

This post tells you how to solve the error assets file project.assets.json not found in Visual Studi…

Read Post

Code to help you debug an umbraco issue on a remote site

This post gives you some razor code to help you see the values of the IPublishedContent item's prope…

Read Post

How to fix the 403 error on preview in Umbraco after upgrading

This post shows you how to fix the 403 error on preview after you have upgraded it.

Read Post