Routes dependent on subdomain


I'm having little problem getting my idea to work, would be very
thankful if you could help me.

I have one Ruby on Rails application sitting on server, and multiple
subdomains, pointing to the same server/app. For example:

I want to have exactly the same app and exactly the same routes on
all, except that I want to map root of to different
controller than other. For example: => MainController => UserController => UserController

Any ideas how can I do it using Rails routes? Or possibly URL rewrite
in Apache proxy?

I am also considering different approach - I will have 2 applications
running, and share part of code (models, some base controllers), and
map main web page to different instance than all other subdomains.

Thanks and best,