Forum: Ruby on Rails Routing based on host domain

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Gerry Shaw (Guest)
on 2006-02-26 07:33
I'm having some problems getting routes to work based on the incoming
host domain.

Imagine the top level domain for my app is foo.com.  If the user comes
in with a request of:
* http://foo.com
* http://www.foo.com

I would like to route them to the public home page

If they come in with anything else I want to route them to their account
home page, i.e.:
* http://apple.foo.com
* http://banana.foo.com

I've been using the account_location plugin to help with the parsing and
redirecting of the account subdomains which works great.  What I can't
figure out is the routing.  I would like to write something like this:

map.public_home   '', :controller => 'page', :action => 'home',
  :requirements => { :host => /^(www\.)?foo\.com$/i }

map.account_home  '', :controller => 'account', :action => 'view'

So when the request goes through the table it would call the correct
controller/action based on the host requirement.  If the host is
www.foo.com or foo.com (no subdomain) it goes to the home page,
otherwise go to the account hoem.

What actually happens is the :requirements are ignored and the first
route always handles.  I have some hackery in there to redirect to the
correct location but I'd rather handle this the "correct way".

Any suggetions?
This topic is locked and can not be replied to.