I'm attempting to write a guide to permenantly redirect a domainname to a different domain title

RewriteCond %{HTTP_HOST} ^www.companyname1.com$
RewriteRule ^(.*)$ http://www.companyname2.com/$1 [R=301,L]

This only works when the user takes note of to key in www, when the user doesn't key in www within the url, the page will load however the image links is going to be damaged.

Does anybody understand how to adjust the above mentioned rule into it works together with and without www?

I'm utilizing a Light configuration, apache 2 on redhat.

You are able to supply several optional Rewrite-Conditions with [OR]:

RewriteCond %{HTTP_HOST} ^www.companyname1.com$ [OR]
RewriteCond %{HTTP_HOST} ^companyname1.com$
RewriteRule ^(.*)$ http://www.companyname2.com/$1 [R=301,L]

This will have the desired effect. The very first Rewrite-Condition fires, if www exists, the 2nd one fires, if www continues to be forgotten.