Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails route based on virtual host (Host HTTP header)

Is it possible to specify a Ruby on Rails route based on the host part of the request URL?

In config/routes.rb, I have

root :to => 'entities#index'

but I would like to use the same code base to serve several sites, each with their own default controller.

like image 771
Eero Avatar asked May 15 '11 13:05

Eero


1 Answers

You can use Request Base Constraints

root :to => "siteone#index", :constraints => {:host => "siteone"}
root :to => "sitetwo#index", :constraints => {:host => "sitetwo"}

Hope this helps.

like image 127
JCorcuera Avatar answered Oct 04 '22 06:10

JCorcuera