how to redirect any subdomain to main domain using .htaccess

hello,
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 ^ http://mydomain.com/ [L,R]

but not working, have any solution?

Use exactly these, just replace your domain.

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

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

1 Like

Hi, maybe this helps:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^webmail.canamhosting.ao$ [OR]
RewriteCond %{HTTP_HOST} ^webmail.canamhosting.ao$
RewriteRule ^(.*)$ https://canamhosting.ao:8090/rainloop/$1 [R=301,L]