# Routing by subdomain problem

**URL:** <https://www.ruby-forum.com/t/routing-by-subdomain-problem/89163>\
**Category:** Rails\
**Created:** [March 17, 2007, 11:13pm UTC](https://www.ruby-forum.com/t/routing-by-subdomain-problem/89163 "2007-03-17T23:13:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ehudros](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ec8ea/32.png) [@ehudros](https://www.ruby-forum.com/u/ehudros)\
**Post date:** [March 17, 2007, 11:13pm UTC](https://www.ruby-forum.com/t/routing-by-subdomain-problem/89163/1 "2007-03-17T23:13:38Z")

</div>

hi everyone,  
I’m trying to set up a routing command so that the ‘www’ subdomain would  
always be directed to my ‘site’ controller, while all other subdomain  
urls (like [username.localhost.com](http://username.localhost.com))be sent to the ‘user’ controller.

I have installed the request routing plugin  
([http://wiki.rubyonrails.org/rails/pages/Request+Routing](http://wiki.rubyonrails.org/rails/pages/Request+Routing))

and this is what i have in routes.rb:  
map.connect ‘’, :controller =\> ‘site’, :requirements =\> { :subdomain =\>  
‘www’}  
map.connect ‘’, :controller =\> ‘user’, :action =\> ‘index’

It seems that no matter what subdomain I call ([www.localhost.com](http://www.localhost.com) /  
[myuser.localhost.com](http://myuser.localhost.com)) it always gets routed to the site controller.

Also, how is it possible to route the following url to an account  
controller:  
[www.localhost.com/account/logout](http://www.localhost.com/account/logout)?  
there is no id in this url - will the following route work:  
map.connect ‘:controller/:action/’?  
How can I only route it if the controller is ‘account’?

Thanks!  
Ehud

---

<div class="post-metadata">

**Author:** ![ehudros](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ec8ea/32.png) [@ehudros](https://www.ruby-forum.com/u/ehudros)\
**Post date:** [March 17, 2007, 11:42pm UTC](https://www.ruby-forum.com/t/routing-by-subdomain-problem/89163/2 "2007-03-17T23:42:12Z")

</div>

On Mar 17, 2007, at 11:13 PM, Ehud R. wrote:

> I have installed the request routing plugin  
> ([http://wiki.rubyonrails.org/rails/pages/Request+Routing](http://wiki.rubyonrails.org/rails/pages/Request+Routing))
> 
> and this is what i have in routes.rb:  
> map.connect ‘’, :controller =\> ‘site’, :requirements =\>  
> { :subdomain =\>  
> ‘www’}

It is right, only :requirements should be :conditions.

> Also, how is it possible to route the following url to an account  
> controller:  
> [www.localhost.com/account/logout](http://www.localhost.com/account/logout)?  
> there is no id in this url - will the following route work:  
> map.connect ‘:controller/:action/’?  
> How can I only route it if the controller is ‘account’?

It just works with default routes, note that you don’t need it in the  
canonical CRUD’s index/list actions.

– fxn

---

<div class="post-metadata">

**Author:** ![ehudros](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ec8ea/32.png) [@ehudros](https://www.ruby-forum.com/u/ehudros)\
**Post date:** [March 17, 2007, 11:55pm UTC](https://www.ruby-forum.com/t/routing-by-subdomain-problem/89163/3 "2007-03-17T23:55:58Z")

</div>

hmmm, it seems that even when I change it to :conditions it still routes  
to the site/index:

map.connect ‘’, :controller =\> ‘site’, :action=\>‘index’, :conditions =\>  
{ :subdomain =\> ‘www’}

and the url i access is: [test.localhost.com:3001](http://test.localhost.com:3001).  
I get routed to the main site instead of to the account controller.

Any idea why?  
Thanks!

---

<div class="post-metadata">

**Author:** ![ehudros](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ec8ea/32.png) [@ehudros](https://www.ruby-forum.com/u/ehudros)\
**Post date:** [March 18, 2007, 12:08am UTC](https://www.ruby-forum.com/t/routing-by-subdomain-problem/89163/4 "2007-03-18T00:08:35Z")

</div>

Is there anything I should do excpet plguin/install the request\_routing  
plug in?  
Do i have to use it somewhere in my application?

---

<div class="post-metadata">

**Author:** ![ehudros](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ec8ea/32.png) [@ehudros](https://www.ruby-forum.com/u/ehudros)\
**Post date:** [March 18, 2007, 12:06am UTC](https://www.ruby-forum.com/t/routing-by-subdomain-problem/89163/5 "2007-03-18T00:06:15Z")

</div>

On Mar 17, 2007, at 11:55 PM, Ehud R. wrote:

> I get routed to the main site instead of to the account controller.
> 
> Any idea why?

It’s strange, these routes are working for me:

map.connect ‘’, :controller =\> “public”, :action =\>  
‘index’, :conditions =\> {:subdomain =\> ‘www’}  
map.connect ‘’, :controller =\> “invoices”, :action =\> ‘new’

They seem analogous to yours.

– fxn

---

<div class="post-metadata">

**Author:** ![ehudros](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3ec8ea/32.png) [@ehudros](https://www.ruby-forum.com/u/ehudros)\
**Post date:** [March 18, 2007, 12:35am UTC](https://www.ruby-forum.com/t/routing-by-subdomain-problem/89163/6 "2007-03-18T00:35:18Z")

</div>

On Mar 18, 2007, at 12:08 AM, Ehud R. wrote:

> Is there anything I should do excpet plguin/install the  
> request\_routing  
> plug in?

The server needs a restart to load the plugin (that happens with any  
plugin), nothing else.

– fxn
