Redirect non-www domain to www using htaccess for seo

If you own a website running under your own domain, then you probably already understand the importance of SEO. One of the easiest and most important things to improve your SEO health is to avoid duplicate links in your content. So, make sure that you are not serving both www.yourdomain.com and yourdomain.com links separately. Ideally you should be 301 redirecting one to another (for understanding different redirects, check out seomoz article) to not dilute your SEO karma between www and non-www links.

I will just cover how I did it on webfaction. To check out how to do this on any other hosting provider, you can google ‘301 redirect htaccess <yourhostname>’

On your webfaction control panel, do the following-

  1. Create a new Static/CGI/PHP App – let’s call it dummyapp.
  2. Create a new website mapping http://yourdomain.com to dummyapp. If you were mapping both www and non-www domain to your working app before, you will need to remove the non-www domain from that app first. You should now have something like below where festsy is the working app and dummyfestsy the new app we created only for redirects.
  3. Now, ssh to your webfaction root and go to webapps/dummyapp/ Remove any file that exists there (such as index.html). Now add a .htaccess file with just one line – Redirect 301 / http://www.yourdomain.com/ Do NOT forget the trailing slash at the end else your extended urls won’t work. Save and close.
  4. Go to a browser and test http://yourdomain.com It should redirect to http://www.yourdomain.com Also try an extended url to be safe e.g. http://festsy.com/browse in my case. If you set up the trailing slash correctly in previous step, this should redirect to http://www.festsy.com/browse

And, that’s it! I found this to be the easiest way for redirections. Hope it helps.

  

Leave a Reply

Your email address will not be published.