Add www to your domain or remove the www from your domain

Add www in front of your domain
This is important not only for aesthetic reasons, but for SEO (Search Engine Optimization). Forcing www before your domain or removing it prevents search engines from ending up with duplicate results and different page ranks per page. Some websites don‘t even return a page when you leave out the www. This depends on how your webserver is set up. To force the www to be added before the domain, make a .htaccess file in your root folder of your website containing these lines:
RewriteEngine On
RewriteCond % ^domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
You have to fill in your domain on the first line and second line. The R=301 flag means the user is going to be visually redirected to the domain containing the www in front of it.
Remove www from your domain
To remove the www from your domain, do the same as above but with these lines:
RewriteEngine On
RewriteCond % ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]