It's can be done via .htaccess because invalid subdomains are not hit into valid virtual host.
Think it can be done via wildcard CNAME DNS record via Tools&Settings > DNS template (but please test it first on some test site)
(Pay attention that this operation may be not applied for domains with customized DNS records)
(Pay attention that if you tried to force applying DNS template than all domains DNS customization may be lost(I've not remember exactly this bihaviour))
In case you can't use DNS template you always can add new DNS records to every domain automatically via command /usr/local/psa/bin/dns