Most websites stick to one form of their domain name when they refer to their own site, be it the plain domain name, like example.com, or the www form, like www.example.com. Unfortunately others linking to you don't always follow your preferred style. If some sites link to you with just the domain name, and others link using the www subdomain, then your site may face issues with the search engines. This article shows you how you can work around the problem by automatically redirecting all URL requests of one form to the other in a search engine friendly way.
Having your site referred to as both example.com and www.example.com is not a problem of consistency. Neither is it an issue that affects branding, since most humans looking at those two hostnames will automatically assume they are referring to the same thing. In fact, most humans, when told to go to a domain like "thesitewizard.com" will automatically type "www.thesitewizard.com" in their browsers, since this is the way the majority of the websites on the Internet work, and they know it. So the problem isn't really with human beings at all.
The way to deal with it is to redirect all pages using one form of the web address ("URL") to the other form, using what is known as a "301" (or "permanent") redirection code. When the search engines see the redirection along with the 301 code, it will realise that that particular page has been permanently relocated to another address. (Don't worry if you don't understand this paragraph. It's just an overview of what you'll be doing later in this article.)
- Your website must be hosted on an Apache web server. In general, if your site is hosted on a Linux, FreeBSD, or Unix-type server, it is probably using the Apache server. If your site is hosted on a Windows system, this is unlikely to be the case. One way to find out for sure is to ask your web host or check the documentation on their website.
- Your web host must allow you to override your web server's configuration using a .htaccess file. Again, this information is available from your web host.
- Your web host must have installed and enabled the mod_rewrite Apache module
To redirect (say) example.com to www.example.com, add the following code to your .htaccess file.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$
http://www.example.com/$1 [R=301,L]
The above code causes the server to check that the hostname in the URL is example.com. If it is, the visitor will be sent to www.example.com instead.
If you also own, say example.co.uk, example.de and/or some other domain, and want them to be redirected to www.example.com as well, you may prefer to use the following code instead:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$
http://www.example.com/$1 [R=301,L]
This second set of rules checks to see if the URL has a hostname of www.example.com. If it doesn't, the visitor is redirected to www.example.com. In other words, any web address with a hostname other than www.example.com will cause a redirection to take place.
Źródło: http://community.invisionbyte.net/tutorials/article/119-how-to-redirect-urls/?s=537a5823ac2e0531eb024744db17240e
wto, 18 maj 2010