In this tutorial, you will learn how to force your website to always add www for all URLs generated on your website. Probably, one of the most forgotten tasks by developers during a project is to add a rule to enforce either a WWW or non-WWW Url strategy on a website. The WWW/non-WWW debate has been waging for years and a lot of my non-technical clients are unsure of what is the difference between www vs non-www URLs in terms of Episerver? Which rule is the best?

I don't think this confusion is just limited to non-tech people. I'm sure there are a few developers out there who, if they owned up, are still a bit unsure bout which one is better and what strategy they should adopt on their Episerver projects. In today's guide, I'm going to go into this topic in a bit more detail. By the end of this guide, you should have enough knowledge to know how to implement a policy and which one you should use.

What Is The Difference Between WWW and non-WWW URLs?

If you haven't come across this topic before, the choice is based on if your website URLs should have www at the front like this, http://www.website .com, or not like this http://website.com. The second version is obviously shorter and easier for a user to type. Is that the main thing?

Google has stated that they will penalise websites if they allow both types of URLs because a search engine might see it as duplicate content. In terms of an SEO strategy for your website, having the right strategy is key to getting a good page ranking in Google. So here's the good news, Google doesn't care which way you go. For Google, it makes no difference if your website has all WW URLs or non-WWW URLs. All Google cares about is that your website doesn't have duplicate URLs. This means the choice between the two approaches really boils down to a personal choice. The main thing is that you pick one and stick to it.

Technical Difference between WWW vs non-WWW

Episerver will work with both approaches. Personally, I tend to favor using a WWW approach. With a WWW approach, you get a few technical benefits compared to using a naked domain (non-www). Some of these benefits include:

  • WWW give your IT team flexibility when restricting domains internally

  • WWW allows more flexibility if you have different subdomains in your network

  • WWW makes it obvious your URL is a website, when you use a naked domain you don't necessarily know which service you might be working with.

  • Flexibility with DNS (read this guide to learn about this)

Naked domains don't have any technical advantages over WWW. The reason why some people like them is they make URLs shorter. When I make an architectural decision about a website, I tend to make it in terms of the capabilities that will give me the biggest benefit long term. I've always stuck with a WWW approach and I've never had any issues as it gives you more options. Again, the choice is a personal preference so it is up to you!!!

How To Force WWW in Episerver

If you agree with a WWW approach, I will now show you a URL ReWrite rule to enforce this policy on your site. A redirect rule is not the only way to enforce this policy in Episerver, however, I think it is the best way. You could enforce a policy in an Episerver initialization module, or as Alf Nilsson suggested in the 'Redirect' function, in the Admin mode. Adding redirects here would work but the request would take slightly longer to process compared to using an IIS module, as the redirect is happening slightly further down the pipeline.

url_rewrite_pipeline

As you can see from this handy diagram by Microsoft, with a URL ReWrite the request happens at the resolve cache level. An Initialization module will be called in the 'Execute Handler' stage which will add a little bit more overhead. Redirect rules in IIS are in general the quickest place to add redirects in a .NET powered website.

How To Setup A Url Rewrite Redirect?

If I have convinced you a UrlRewrite redirect rule is a way to go, you need to make sure you have UrlRewrite installed on all of your live Episerver nodes. If you use a load-balanced environment, if you forget to add it on, your website will blow up. You can download URL rewrite here. Rules are added in the web.config. In the system.webServer section you will need to add the following config:

This rule will redirect all URLs that don't have a WWW prefix, to use a WWW prefix. That is all you need to do. One rule, simple"


In today's post, we've covered the differences between WWW URLs and non-WWW URLs. My opinion (for what it's worth) is that it doesn't matter which one you use. As long as you pick one and stick with it your SEO won't be affected. My preference is using WWW as it provides some slight technical benefits, however, if I had to use non-WWW I wouldn't lose any sleep over it. Happy Coding 🤘