I've two websites that's really exactly the same where example.com shares all files from good examples.com. So whatever changes produced in exampples.com, example.com instantly will get up-to-date. Which means they have a similar .htaccess file. The issue is, I wish to both sites redirects to non www to some www url. I acquired this:

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

This will get it done:

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

Essentially you are adding an OR condition to express if either example.com or good examples.com does not start with www. then combine it with the particular domain title.

replace example.com with %{HTTP_HOST} to create your rules host independent