how to redirect any subdomain to main domain using .htaccess

im new with cyberpanel, im using this for wordpress, i want redirect any sub-domain to main domain with .htaccess, i was try edit rewrite rules and add this code below LSCACHE and before wordpress rules

RewriteCond %{HTTP_HOST} ^(.+)\.mydomain\.com$ [NC]
RewriteRule ^ [L,R]

but not working, have any solution?

Use exactly these, just replace your domain.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\\.cyberpanel\\.net$   [NC]
RewriteRule ^  [L,R]

You must add rewrite rules following this guide → 6 - Rewrite Rules - CyberPanel

Hi, maybe this helps:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^$ [OR]
RewriteCond %{HTTP_HOST} ^$
RewriteRule ^(.*)$$1 [R=301,L]