Adding subdomain support

I was able to figure out a solution to add subdomain support for issue #352. Let me know what you think and if you want me to make any changes.