11 Jan 2016
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.
Follow along with this video to get you started with Umbraco