.htaccess

Adding the www to .htaccess for multisites

Adding the www to URL in .htaccess for Multisites and handle www issues for canonical URLs.
    ##Adding the www
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
    RewriteRule ^(.*)$ "http://www.%1/$1" [L,R=301]

Opposite to this code you can removing the www from URL.

Removing www from Multi-sites or Subdomains in .htaccess

If you are running a Multisites or Subdomains sites this .htaccess RewriteRule code might come in handy specially for purpose of SEO. You can clean up your URL from http://www.yourdomain.com to http://yourdomain.com and remove the “www” with 301 redirect to non-www.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [L,R=301]

If you want to add the www to URLs check this code out.