Sounds like your doing a free subdomain hosting kind of thing. I made several of these scripts, e107deluxe.com is one of my creations....its fairly easy to do:
Open your httpd.conf file and where you have the record for your domain all the way down the bottom of the file, find thid:
and change it to this:
Save and exit, then restart apache.
Now use the code posted by -NC- to finish it off!