ServerAlias *.domen.com
domen.com
RewriteEngine
On
RewriteCond %{HTTP_HOST} !^www\.domen.com
RewriteCond %{HTTP_HOST} !^cgi-bin\.domen\.com$
RewriteCond %{HTTP_HOST} ^(www\.)?(([^\.]+)\.){1}domen.com$
RewriteCond /home/login/public_html/%3 -d
RewriteRule ^/(.*) /%3/$1
Для удобства предлагаю сервис: