# Simple Subdomain Routing

**URL:** <https://www.ruby-forum.com/t/simple-subdomain-routing/64021>\
**Category:** Rails\
**Created:** [June 21, 2006, 1:23pm UTC](https://www.ruby-forum.com/t/simple-subdomain-routing/64021 "2006-06-21T13:23:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![iluke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c6cbf5/32.png) [@iluke](https://www.ruby-forum.com/u/iluke)\
**Post date:** [June 21, 2006, 1:23pm UTC](https://www.ruby-forum.com/t/simple-subdomain-routing/64021/1 "2006-06-21T13:23:34Z")

</div>

Hey all,

I hope this is a relitively simple question, but I have not been able to  
arrive at a workable solution for myself.

What I’m wanting to do is a very simple pattern match on a subdomain:  
www.\* forwards to [mydomain.com/www\_controller](http://mydomain.com/www_controller)

and everything else forwards to [mydomain.com/other\_controller](http://mydomain.com/other_controller)

The idea is to forward logged in users to [username.mydomain.com](http://username.mydomain.com), but all  
the user’s data is stored in a session, so, it doesn’t need to actually  
do any database lookups or anything like that based on the subdomain,  
only a routing request.

Thanks in advance!  
-Luke

---

<div class="post-metadata">

**Author:** ![iluke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c6cbf5/32.png) [@iluke](https://www.ruby-forum.com/u/iluke)\
**Post date:** [June 21, 2006, 2:58pm UTC](https://www.ruby-forum.com/t/simple-subdomain-routing/64021/2 "2006-06-21T14:58:35Z")

</div>

This might be useful to you: [http://agilewebdevelopment.com/plugins/](http://agilewebdevelopment.com/plugins/)  
request\_routing

–  
Benjamin C.  
[http://www.bencurtis.com/](http://www.bencurtis.com/)  
[http://www.tesly.com/](http://www.tesly.com/) – Collaborative test case management  
[http://www.agilewebdevelopment.com/](http://www.agilewebdevelopment.com/) – Resources for the Rails community

---

<div class="post-metadata">

**Author:** ![iluke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c6cbf5/32.png) [@iluke](https://www.ruby-forum.com/u/iluke)\
**Post date:** [June 22, 2006, 12:32am UTC](https://www.ruby-forum.com/t/simple-subdomain-routing/64021/3 "2006-06-22T00:32:56Z")

</div>

@ benjamin:

Thanks so much for the link. I’ve installed the plugin, but I cannot  
seem to get it working (yes, I really am that dense).

I have two controllers, ‘site’ and ‘user’. I would like all routs going  
to ‘www’ to go to the site controller, and everything else to user,  
however, I cannot get the pieces all glued together.

```auto
map.connect '', :controller => 'site', :requirements => { :subdomain => 
'www' }
```

When I test that (at the top of my routes.rb file), I simply get:  
Recognition failed for “/”

However, if I tack on the /site to the url (www.localhost:3000/site), I  
get exactly what I would expect (the `index` method).

Any suggestions? I’ve poked around the net for some further  
documentation for the plugin, but I haven’t really come across a whole  
lot.

---

<div class="post-metadata">

**Author:** ![iluke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c6cbf5/32.png) [@iluke](https://www.ruby-forum.com/u/iluke)\
**Post date:** [June 22, 2006, 10:21am UTC](https://www.ruby-forum.com/t/simple-subdomain-routing/64021/4 "2006-06-22T10:21:08Z")

</div>

JÃ³n BorgÃ¾Ã³rsson wrote:

> It might not be recognizing www as your subdomain because it’s not the  
> third name. Thus thinking www is your domain and .local to be the  
> equivalent to .com.  
> Instead try putting in the host [www.localhost.com](http://www.localhost.com) to your hosts table  
> and try that.

Oh my goodness! Of course. I think it’s time I take a break from the  
computer for a while – maybe my eyes will go un-crossed and I’ll be  
able to see straight again.

Thank you so much!!  
-LW

---

<div class="post-metadata">

**Author:** ![iluke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/c6cbf5/32.png) [@iluke](https://www.ruby-forum.com/u/iluke)\
**Post date:** [June 22, 2006, 7:37am UTC](https://www.ruby-forum.com/t/simple-subdomain-routing/64021/5 "2006-06-22T07:37:19Z")

</div>

It might not be recognizing www as your subdomain because it’s not the  
third name. Thus thinking www is your domain and .local to be the  
equivalent to .com.  
Instead try putting in the host [www.localhost.com](http://www.localhost.com) to your hosts table  
and try that.

On 6/21/06, Luke W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> map.connect ‘’, :controller =\> ‘site’, :requirements =\> { :subdomain =\>  
> documentation for the plugin, but I haven’t really come across a whole  
> lot.
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–
