The Blog

Check out our brand new Joomla! Template Club:
InspireTheme.com

Redirecting non-www to www (HOW? and WHY?)

Redirecting non-www to www (HOW? and WHY?) - 5.0 out of 5 based on 3 votes

This is a widely discussed topic the last few years. The non-www to www redirection is also know as URL Canonicalization and it is very important for your SEO. It is very important for both - your PR (Page Rank) and SERP (Search Engine Result Page).

Why Should I Redirect non-www to www?

There are several reasons to do that. For example, if you have not redirected your non-www to www you will have two versions of your website. Sometimes you will see your website in the Browser as example.com and sometimes you will see it as www.example.com. Now, people will link to your website (backlinks) in both ways - some of them will link to example.com and others will link to www.example.com. That's how your Page Rank will be split over two different versions instead of preserving the link juice just on one version. Let's say you have 100 backlinks to example.com and 50 backlinks to www.example.com - your website will NOT have 150 backlinks. But if you have redirected the non-www to www you will have exactly 150 backlinks to your website.

Imagine that you have not implemented 301 redirection from non-www to www, then suppose people link to a page on your site using non-www and www at the same time from different places. Then search engines (Google) can get confused as to which URL to throw into their index and since they have 2 URLs with the same content on your site they will see it as duplicate content and this is bad for your SERP.

You might also want to read this Article from Matt Gutts which will give you a lot of information about the topic.

How to Redirect non-www to www in my Joomla Site?

There are many different ways to do that. During the years I have used different codes in the .htaccess file and different Joomla Plugins to handle the URL Canonicalization and redirect the non-www to www. I convinced myself that the best way to do that is using the .htaccess file. The only thing you need to be aware of is the particular code you need to add to the .htaccess file and where exactly you need to add it.

So, here it is. There are different opinions about the exact code but the one and only proper code is this:

RewriteCond %{HTTP_HOST} !^(www\.joomfx\.com)?$
RewriteRule (.*) http://www.joomfx.com/$1 [R=301,L]

Make sure you replace "joomfx" with your website :)

You need to add this code in the proper place in the .htaccess file. Everything is explain in there. Here is how your .htaccess should look at the end:

## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.

RewriteCond %{HTTP_HOST} !^(www\.joomfx\.com)?$
RewriteRule (.*) http://www.joomfx.com/$1 [R=301,L]

## End - Custom redirects

So basically, that's it. The above solution is valid for both Joomla 2.5 and Joomla 3.x.

Additional Resources

Joomla Forum Topic 1
Joomla Forum Topic 2

I would love to hear your opinion about the URL Canonicalization so please do not hesitate to use the Comment Form below :)

Ivo Valkov

I'm a front end developer. I love creating things, playing football, snowboarding and so on. I also hope you like all our stuff. We started using Gantry for our projects and honestly, we love it!

Website: joomfx.com