# Routes dependent on subdomain

**URL:** <https://www.ruby-forum.com/t/routes-dependent-on-subdomain/143818>\
**Category:** Rails\
**Created:** [July 23, 2008, 1:18am UTC](https://www.ruby-forum.com/t/routes-dependent-on-subdomain/143818 "2008-07-23T01:18:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hubert\_SSSSSSSSSpic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/73ab20/32.png) [@Hubert\_SSSSSSSSSpic](https://www.ruby-forum.com/u/Hubert_SSSSSSSSSpic)\
**Post date:** [July 23, 2008, 1:18am UTC](https://www.ruby-forum.com/t/routes-dependent-on-subdomain/143818/1 "2008-07-23T01:18:49Z")

</div>

Hi,

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:

> **[MainServer.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=mainserver.com)**
>
> 100% satisfaction guaranteed. Hassle-free shopping. We help you find the right domain name.

[user1.mainserver.com](http://user1.mainserver.com)

> **[MainServer.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=mainserver.com)**
>
> 100% satisfaction guaranteed. Hassle-free shopping. We help you find the right domain name.

I want to have exactly the same app and exactly the same routes on  
all, except that I want to map root of [mainserver.com](http://mainserver.com) to different  
controller than other. For example:

[mainserver.com](http://mainserver.com) =\> MainController  
[user1.mainserver.com](http://user1.mainserver.com) =\> UserController  
[user2.mainserver.com](http://user2.mainserver.com) =\> 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,  
H.
