Tutorial

Using a 301 Redirect www or non-www and why you should use it.

Should you set up and configure your site with or without the www? Does your site work with both www or without the www? (http://www.domain.com/) and (http://domain.com/). If so you might consider making it a bit more search engine friendly by choosing your preferred format, and redirecting the other. Continue reading this article for more details about why you should do this and how to do this.

This applies to all websites, not just Boonex Dolphin, but any other website you may have whether it be static html, a php based script, or anything else.

I prefer the www version (http://www.dialme.com/) when I setup and configure sites whether it be here on this site or any other I create. Currently this is the more popular choice of the internet world at this time. Some people prefer the www version of a website, while others prefer the non-www version. That is something you will have to decide for yourself. I just prefer the more common www usage when I set up sites. I also have better luck with cookie handling using the www version.

You should decide early in your sites development, setup, and programming which you prefer. It's better to set it in the beginning rather than change later. If you have an established site that uses the non-www version it could be unwise to switch to the www version as you risk loosing links from other sites that Google and the other search engines already are counting for your site. You could also risk some potential de-indexing in Google as your site links in Google may no longer be valid.

Once you decide which form you are going to use for your site you should redirect the other using a 301 redirect in .htaccess if you have Apache Linux hosting. This is very useful if someone including yourself accidentally links to the opposite of what you use. It is the search engine friendly way of sending them to the version you use, and will pass along any link juice rather than risk loosing it or splitting it.

For example the following may appear to be the same page to you and your visitors:
    domain.com
    domain.com/
    www.domain.com/
    www.domain.com
    domain.com/index.html
    www.domain.com/index.html


But Google as well as many other search engines regard all of these as different pages. They can also potentially consider them duplicate content, and you don't want that to happen.

So a 301 redirect can be used to tell the search engines to sort of consider all of those pages the same as http://www.domain.com/. This will also prevent the search engines from thinking you have duplicate content.

For Apache Linux hosting servers you will need to have mod_rewrite enable on your server. Then, create or add to .htaccess file the following:

For the NON-www. to the www:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^domain\.com
    RewriteRule (.*) http://www.domain.com/$1 [R=301,L]


To Redirect www.mysite.com to mysite.com

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]

Once you have made the changes, verify that everything is working properly.

If for any reason the above code doesn’t work, remove it from your htaccess file and ask for assistance from your web hosting company.

Tips:

When creating links whether on your own site or when posting a link to your site elsewhere...

    ALWAYS:
    <a href="http://www.yourdomain.com/">
    NEVER:
    <a href="http://www.yourdomain.com/index.html"> -Not direct to the domain.
    <a href="http://www.yourdomain.com"> - No Trailing Slash


For those of you running Boonex Dolphin please see this article:
Dolphin with www prefix or non-www-version

 
Written By
Tutorial by: Jeremy LeSarge (AKA Ray)

I am the owner and administrator of DialMe.com. I write Tutorials for Boonex Dolphin as well as tips and resources surrounding website programming and development. I enjoy working with WordPress, SEO, and Web Hosting / Servers. I also maintain a WordPress Blog here on this site where you will find a variety of technology and webmaster resources.

Actions
Recommend
Sponsored Links