# Single Rails App - Several Subdomains

**URL:** <https://www.ruby-forum.com/t/single-rails-app-several-subdomains/150755>\
**Category:** Rails\
**Created:** [October 12, 2008, 5:48pm UTC](https://www.ruby-forum.com/t/single-rails-app-several-subdomains/150755 "2008-10-12T17:48:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gamehack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a3d4f5/32.png) [@gamehack](https://www.ruby-forum.com/u/gamehack)\
**Post date:** [October 12, 2008, 5:48pm UTC](https://www.ruby-forum.com/t/single-rails-app-several-subdomains/150755/1 "2008-10-12T17:48:51Z")

</div>

Hi all,

I am in a situation that I have no idea how to approach. Basically,  
I’ve got a licensing app that is distributed across several domains,  
as in:  
[admin.example.com](http://admin.example.com)  
[licenses.example.com](http://licenses.example.com)  
[secure.example.com](http://secure.example.com)  
[paypal.example.com](http://paypal.example.com)  
…

Ideally, I would like to be able to setup routing on a subdomain basis  
but this is not possible with Rails\* (I saw some results on Google  
about people trying to do this but none of the solutions were  
completely working in a integrated fashion throughout the whole  
framework)

I also looked around at other frameworks but I didn’t find one which  
handled this sort of situations properly. The other option I was  
thinking about was using the same model objects in different apps for  
each subdomain but I’m not sure whether this is the right way handle  
this sort of thing. Any tips on how to approach the problem are  
greatly appreciated.

Thanks,  
M

- Correct me if I’m wrong

---

<div class="post-metadata">

**Author:** ![gamehack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a3d4f5/32.png) [@gamehack](https://www.ruby-forum.com/u/gamehack)\
**Post date:** [October 12, 2008, 6:15pm UTC](https://www.ruby-forum.com/t/single-rails-app-several-subdomains/150755/2 "2008-10-12T18:15:13Z")

</div>

On Sun, Oct 12, 2008 at 8:48 AM, gamehack [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’ve got a licensing app that is distributed across several domains,  
> as in:  
> [admin.example.com](http://admin.example.com)  
> [licenses.example.com](http://licenses.example.com)  
> [secure.example.com](http://secure.example.com)  
> [paypal.example.com](http://paypal.example.com)

> Ideally, I would like to be able to setup routing on a subdomain basis  
> …  
> thinking about was using the same model objects in different apps for  
> each subdomain

It’s not clear to me what you’re trying to achieve – how would the  
response to a request for `secure.example.com/foo` differ from the  
request for `paypal.example.com/foo`, for instance?

Or to put it another way, _can_ these subdomains operate logically  
as uncoupled applications, or are they more `example.com/paypal/`  
and `example.com/secure/`?

If you do need them all serviced by one app, fronting it with Apache  
httpd with mod\_rewrite would probably take care of it.

## HTH,

Hassan S. ------------------------ removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![gamehack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a3d4f5/32.png) [@gamehack](https://www.ruby-forum.com/u/gamehack)\
**Post date:** [October 12, 2008, 6:42pm UTC](https://www.ruby-forum.com/t/single-rails-app-several-subdomains/150755/3 "2008-10-12T18:42:09Z")

</div>

On Oct 12, 5:14 pm, “Hassan S.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > each subdomain
> 
> It’s not clear to me what you’re trying to achieve – how would the  
> response to a request for `secure.example.com/foo` differ from the  
> request for `paypal.example.com/foo`, for instance?

Their URLs would form an empty intersection but [secure.example.com](http://secure.example.com)  
would map ‘’ to the StoreController while [admin.example.com](http://admin.example.com) would map  
‘’ to the AdminController.

> Or to put it another way, _can_ these subdomains operate logically  
> as uncoupled applications, or are they more `example.com/paypal/`  
> and `example.com/secure/`?

They can work as [example.com/secure/](http://example.com/secure/) and [example.com/paypal/](http://example.com/paypal/) etc. I’m  
not sure if that matters but [secure.example.com](http://secure.example.com) would have to go  
through SSL.

> If you do need them all serviced by one app, fronting it with Apache  
> httpd with mod\_rewrite would probably take care of it.

That brings up the question on how to handle URL generation, since a  
URL for the admin controller would have to generate [admin.example.com](http://admin.example.com)  
instead of [example.com/admin](http://example.com/admin).

Thanks,  
M

---

<div class="post-metadata">

**Author:** ![gamehack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a3d4f5/32.png) [@gamehack](https://www.ruby-forum.com/u/gamehack)\
**Post date:** [October 12, 2008, 7:15pm UTC](https://www.ruby-forum.com/t/single-rails-app-several-subdomains/150755/4 "2008-10-12T19:15:37Z")

</div>

On Sun, Oct 12, 2008 at 9:41 AM, gamehack [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > If you do need them all serviced by one app, fronting it with Apache  
> > httpd with mod\_rewrite would probably take care of it.

I’d still consider whether multiple loosely coupled apps would be  
suitable, even desirable – but in any case…

> That brings up the question on how to handle URL generation, since a  
> URL for the admin controller would have to generate [admin.example.com](http://admin.example.com)  
> instead of [example.com/admin](http://example.com/admin).

True. Again, if you’re willing to stick with Apache httpd, mod\_filter or  
mod\_substitute might be appropriate (rewrite the outbound URLs ).

But generating them directly would obviously be preferable. Time to  
go experiment a bit 🙂

FWIW,

## H\*

Hassan S. ------------------------ removed\_email\_address@domain.invalid
