I can do it with the code below
RewriteEngine On
RewriteCond %{HTTP_HOST} ^ex\.mydomain\.com$
RewriteRule ^(.*)$ http://mydomain.com/forums/ex/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^ex2\.mydomain\.com$
RewriteRule ^(.*)$ http://mydomain.com/forums/ex2/$1 [L,R=301]
RewriteCond %{HTTP_HOST}...