Introduction
When you write a URL for your website, it can be written with or without "www," like this:
Should you include "www" with your URL?
The same and not the same
With most websites, the URLs with and without "www" in them will point to the same site. However, you can specify each URL (with and without "www") to point to a different IP address by modifying your DNS A record.
Choose www or no www
Some search engines see the above two URLs as two different URLs. Each URL can have a different PageRank, and by using both, you're diluting the PR for each URL.
For PR and SEO purposes, it's preferable to choose one version or the other to use. There are reasons for each choice. Which one you choose depends mostly on personal preference.
Reasons to include www
- It helps identify a URL as a web address, especially if the domain extension is other than a .com one.
- Many people will type it in anyway.
- For some people, URLs look more visually appealing with them.
Reasons not to include www
- It makes the URL longer, especially if the URL is for a subdomain.
- It's unnecessary.
- For some people, URLs look cleaner without them.
How to redirect from one to the other using .htaccess
If your site is on an Apache server, you can choose to have only the version with or without "www" appear. One will direct to the other.
Add one of the following to your .htaccess file after replacing "example.com" with your domain. The "RewriteEngine on" first line activates mod_rewrite.
To redirect to the URL with www
RewriteEngine On
rewriteCond %{HTTP_HOST} ^example.com [NC]
rewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
To redirect to the URL without www
RewriteEngine on
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
RewriteRule ^/(.*) http://%1/$1 [L,R=301]