# Route 1st domain to a controller, 2nd domain to con/act/id

**URL:** <https://www.ruby-forum.com/t/route-1st-domain-to-a-controller-2nd-domain-to-con-act-id/61790>\
**Category:** Rails\
**Created:** [May 27, 2006, 11:00am UTC](https://www.ruby-forum.com/t/route-1st-domain-to-a-controller-2nd-domain-to-con-act-id/61790 "2006-05-27T11:00:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ac91a4/32.png) [@bill](https://www.ruby-forum.com/u/bill)\
**Post date:** [May 27, 2006, 11:00am UTC](https://www.ruby-forum.com/t/route-1st-domain-to-a-controller-2nd-domain-to-con-act-id/61790/1 "2006-05-27T11:00:13Z")

</div>

I’m having trouble with mapping a first domain to:

```
map.connect ':action', :controller => 'admin'

```

I can get that to work, and I’d be fine if there’s only one domain  
pointing to my app.

However, I will point several domains to the app, so I only want that  
route for one domain.

I’ve tried:

```
map.connect ':action', :controller => 'admin' if @request.host == 

```

‘[domain.com](http://domain.com)’

but I get an error about nil.host. I’m not sure but it seems @request  
is undefined in routes.rb.

How might I get this done?

Thanks,  
Bill

---

<div class="post-metadata">

**Author:** ![bill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ac91a4/32.png) [@bill](https://www.ruby-forum.com/u/bill)\
**Post date:** [May 27, 2006, 11:46am UTC](https://www.ruby-forum.com/t/route-1st-domain-to-a-controller-2nd-domain-to-con-act-id/61790/2 "2006-05-27T11:46:58Z")

</div>

> I’ve tried:
> 
> ```
> map.connect ':action', :controller => 'admin' if @request.host ==
> 
> ```
> 
> ‘[domain.com](http://domain.com)’
> 
> but I get an error about nil.host. I’m not sure but it seems @request  
> is undefined in routes.rb.
> 
> How might I get this done?

Hello Bill,

You should take a look at the Rails “Request Routing” plugin  
mentioned in the following post:  
[http://weblog.rubyonrails.org/articles/2006/05/22/dan-webbs-request-](http://weblog.rubyonrails.org/articles/2006/05/22/dan-webbs-request-)  
routing-plugin

It looks like it will fullfill your need.

Roman

---

<div class="post-metadata">

**Author:** ![bill](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ac91a4/32.png) [@bill](https://www.ruby-forum.com/u/bill)\
**Post date:** [May 27, 2006, 3:15pm UTC](https://www.ruby-forum.com/t/route-1st-domain-to-a-controller-2nd-domain-to-con-act-id/61790/3 "2006-05-27T15:15:07Z")

</div>

> You should take a look at the Rails “Request Routing” plugin  
> mentioned in the following post:  
> [http://weblog.rubyonrails.org/articles/2006/05/22/dan-webbs-request-](http://weblog.rubyonrails.org/articles/2006/05/22/dan-webbs-request-)  
> routing-plugin

That looks good. A little more digging reveals routes.rb is set once,  
before @request is set.

The plugin is a nice work around.

Thanks,  
Bill
