You can use these type of rules:
RewriteBase /
RewriteCond %{HTTP_HOST} ^(?:www\.)?domain1\.com$ [NC]
RewriteRule ^ http://someotherdomain1.com%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{HTTP_HOST} ^(?:www\.)?domain2\.com$ [NC]
RewriteRule ^ http://someotherdomain2.com%{REQUEST_URI} [R=301,L,NE]
Alternatively if you have access to Apache config then you can utilize RewriteMap
feature and have just one single rule here like this:
RewriteCond %{HTTP_HOST} ^(?:www\.)?([^.]+)\.com$ [NC]
RewriteRule ^ http://${domainMap:%1}.com%{REQUEST_URI} [R=301,L,NE]
In your Apache config you need to define domainMap
as:
RewriteMap domainMap txt://path/to/domain-map.txt