Subdomain to subdomain 301 redirect

i want to make 301 redirect (subdomain to subdomain).
i use this.(it works on vesta panel)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^x\.com$ [OR]
RewriteCond %{HTTP_HOST} ^y\.x\.com$
RewriteRule (.*)$ https://y.z.com/$1 [R=301,L]
doesn’t work for me.
Do you have any ideas ?