Redirect non www record to www record via .htaccess

To avoid search engines indexing your site under the www record and non www record, you can redirect the non www record to the www record. From a user point of view this means that when I browse to domainname.com, I am redirected to www.domainname.com.

Create a .htaccess file

Add the following lines to it, replacing domainname.com with your domain name: