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.

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?

Paul Seal

A .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.

Web: codeshare.co.uk

Comments

Share Top