# Subdomains, Routing, and Subdirectory Controllers

**URL:** <https://www.ruby-forum.com/t/subdomains-routing-and-subdirectory-controllers/90755>\
**Category:** Rails\
**Created:** [April 1, 2007, 12:49am UTC](https://www.ruby-forum.com/t/subdomains-routing-and-subdirectory-controllers/90755 "2007-04-01T00:49:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jtcalhoun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e79b87/32.png) [@jtcalhoun](https://www.ruby-forum.com/u/jtcalhoun)\
**Post date:** [April 1, 2007, 12:49am UTC](https://www.ruby-forum.com/t/subdomains-routing-and-subdirectory-controllers/90755/1 "2007-04-01T00:49:18Z")

</div>

For reference, this question is similar to “Subdomains, Session Data,  
& Routing” posted Oct. 31, 2006. Link:

## [http://groups.google.com/group/rubyonrails-talk/browse\_thread/thread/d3c5072c3588a1e0/f87d0fdfded31650](http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/d3c5072c3588a1e0/f87d0fdfded31650)

I would like to set up a subdomain and, using the request\_routing  
plugin, have requests to that subdomain call corresponding “sub-  
controllers” inside a controller module. That way, urls like:

[http://sub.example.com/target/myaction](http://sub.example.com/target/myaction)

could be routed to call:

Grouped::TargetController#myaction (located in /app/controllers/  
grouped/target\_controller.rb)

I realize one solution would be to use “Option #2” in the referenced  
post above and create an action dedicated to parsing the url and  
redirecting to the appropriate controller/action. However, I was  
wondering if a simpler approach could be taken through the routing  
code by doing something along these lines:

# match [sub.example.com](http://sub.example.com)

map.with\_options :conditions =\> { :subdomain =\> ‘sub’ } do |sub|  
sub.connect ‘:target/:action/:id’, :controller =\> “sub/:target”  
end

Any help would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![jtcalhoun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e79b87/32.png) [@jtcalhoun](https://www.ruby-forum.com/u/jtcalhoun)\
**Post date:** [April 1, 2007, 1:09am UTC](https://www.ruby-forum.com/t/subdomains-routing-and-subdirectory-controllers/90755/2 "2007-04-01T01:09:20Z")

</div>

Note: The route in the example code should read:

sub.connect ‘:target/:action/:id’, :controller =\> “grouped/:target”
