I actually use something similiar for a script, however I was able to do it without htaccess files.
The only tricky part is if someone uses a
www.SOMETHING.yourdomain.com, but I added a if/then to just say if they did that then to use the $domain as the $host.