Permanent 301 Redirect domain.com To www.domain.com in Umbraco

Umbraco Developer TutorialMost SEO experts say that when you have two or more domains or URLs that have duplicate content, then Google will penalize you. Google and SEO experts recommend that you use 301 redirects to tell search engines that you have duplicate content and to forward to the correct domain or url.

This is something we generally do in IIS (see How to 301 Redirect example.com to www.example.com in IIS), but sometimes hosts don't give you access to IIS and you have to make do.

I found and tweaked this from an old forum post ( url rewrite for http://domain.com to http://www.domain.com - Thanks Bob!).

1. Go to your "Config" directory in your main Umbraco website directory.

2. Edit the "URLRewriting.config" file in your favorite text editor.

3. Add the following code between the <rewrites>(paste here)</rewrites> tags:

<add name="SEOfix"  virtualUrl="^http\://domain.com/(.*)" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="http://www.domain.com/$1" redirect="Domain" redirectMode="Permanent" ignoreCase="true" />

<add name="SEOfixSSL"  virtualUrl="^https\://domain.com/(.*)" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="https://www.domain.com/$1" redirect="Domain" redirectMode="Permanent" ignoreCase="true" />

4. Save the file and test.

That's it!

This is clearly a very simple solution.  If you want something more robust, then please check out this post from Mike Taylor: URL Rewriting and SEO.  It has some great discussion and is Umbraco-centric despite the title.  Thanks Stefan for the recommendation!

Author

Jason Prothero

comments powered by Disqus
back to top