Our web app lies at bar.com/myapp
We'll use the HTTP Host Header to work out the username
So need to transparently rewrite foo.bar.com to bar.com/myapp using the URL Rewrite module in IIS
But still need to be able to go to www.bar.com and see the company website and webmail.bar.com, etc.
Got it working:
Add a server wide Inbound Rule:
Match URL: (.*) - check every URL
Condition {HTTP_HOST} ^([^.]+)\.bar\.com - must be a subdomain of bar.com
Condition {HTTP_HOST} Doesn't Match Pattern: webmail\.|mail\. - don't run for webmail. or mail.
Action Rewrite: myapp/{R:1} - redirect to /myapp/ keeping all querystring data