Redirecting from http:// to www
The title is not entirely correct. What I’m showing you here is how to return a 301 (Permanently moved) response to the browser and the search engines, when they access your website via http://websitename.com instead of http://www.websitename.com or www.websitename.com.
The major advantage for this is that you will transfer the Google PageRank from the http:// URL to the http://www URL. As you probably already know, websites have a different PageRank on http://websitename.com than they have on http://www.websitename.com.
This way the links that point to http://websitename.com will no longer give PR to that page, instead it will be transfered to the www version. Also, visitors that access your website via the http:// version will be sent to the http://www version.
You can test this by accessing http://geekpedia.com, and you will be sent to http://www.geekpedia.com.
Enough talk, let’s see how this can be done using htaccess. For Geekpedia.com I used the following:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(.*)\.geekpedia\.com$ [NC]
RewriteRule ^(.*)$ http://www.geekpedia.com/$1 [R=301,L]
If you are already using mod_rewrite, then you won’t need the RewriteEngine on line.
Related posts: