Redirect wildcard subdomain to same subdomain on different domain

I finally found an answer on StackOverflow by @Marty.

Code reproduced here:

RewriteCond %{HTTP_HOST} ^(.+\.)?domain1.com$ [NC]
RewriteRule ^ http://%1domain2.com%{REQUEST_URI} [R=301,L]

You can try something like below.

RewriteCond %{HTTP_HOST} ^(.*)\.domain1\.com [NC]
RewriteRule ^(.*)$ http://%1.domain2.com/$1 [R=301,L]

Let me know if that helps