How to prefix www to your website using htaccess

I was wondering why my new website was not showing www infront of my website name. Even when I search my website through Google and click on the link, there was no www infront of my website name in the URL address bar. This will lead to some bad SEO problems in the future. So, I did a search and found that a small change in the htaccess file can sortout this problem. If you are also facing the same problem, edit your htaccess file. It will be in your www folder in your host server. Edit it and insert the following.

# Make all requests have the www. in them
RewriteEngine on
RewriteCond %{HTTP_HOST} ^websitename\.com
RewriteRule ^(.*)$ http://www.websitename.com/$1 [R=permanent,L]

The # sign indicates that it is a comment. You should also modify the “websitename” string with your actual website name. For example if your website name is shellfish.com then you it should look like

# Make all requests have the www. in them
RewriteEngine on
RewriteCond %{HTTP_HOST} ^shellfish\.com
RewriteRule ^(.*)$ http://www.shellfish.com/$1 [R=permanent,L]

Hope this will be helpful and I will be sharing what I discover through this blog “What I learned Today”