How to Redirect to www with (301 redirect) using
mod_rewrite for a better web site SEO
For a better website SEO it's recommended that you think of
rewritting all your incoming http://yourdomain.com to
http://www.yourdomain.com. That way you will escape from having a
duplicate webpage content.
Still many websites online are not aware that having their website
content available twice whenever accessing both
http://yourdomain.com and http://www.yourdomain.com is a terrible
practice since it's very likely that
(Google, MSN, Bing) Web
Crawlers will crawl and try to index the content of the
website, seing that the content is twice available, they will rank
the website as a website with a duplicate content and th at will
have a direct influence on the
overall site pagerank
One of the possible ways to redirect your incoming requests to
yourdomain.com to go to
www.yourdomain.com is via a
mod rewrite ru le within your
.htaccess file
For the rule to work make sure that the
<Directory>
for the VirtualHost of your website has in it included the Apache
directives
AllowOverride All
As you assure yourself mod rewrite is correctly enabled for your
domain then edit your .htaccess and place in it:
RewriteEngine On RewriteCond %{HTTP_HOST} ^pc-freak.net
RewriteRule (.*) http://pc-freak.net/$1 [R=301,L]
Of course you will have to replace the
pc-freak.net domain
in above example with the your custom domain name.
Now all your incoming Apache requests for domain pc-freak.net will
be automatically using the
301 Redirect
Here it is important to explain that the 301 redirect is the most
efficient and
Search Engine Friendly redirect option for a
webpage r edirect.
The code "301" is interpreted by the web crawlers as "moved
permanently". In other words the content of the previous website is
moved permanent ly to the one where the redirect leads.
Of course there are many other possible ways to implement the 301
redirect, however using mod_rewrite potential is probably the most
efficient one for a dynamic site content.