.htaccess

URL rewriting and add www to .htaccess for hosting multiple domain or multi sites

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

The other way around you can removing the www from URL.

Remove www and rewrite URL for 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 out.