pachl
2006-Oct-30 08:32 UTC
Pretty URLs with Subdomain - URL Rewrite, Request Routing Plugin
Does Rails 1.2 (EDGE) provide a native way to work seamlessly with subdomains? For example, I would like the following incoming request to be routed to the corresponding controller/action: http://sub1.domain.com/show => (:controller => sub1, :action => show) I have been able to accomplish this using the "Request Routing" plugin by specifying a subdomain condition. map.connect ''show'', :controller => ''sub1'', :action => ''show'', :conditions => {:subdomain => ''sub1''} My first problem/question is will I have to map each action of a subdomain/controller. Is there an easier way, possibly a one-liner? My second problem is with the URLs generated by url_for and link_to once the request has been directed to the correct controller/action. How can one reverse the process? For example: url_for(:controller => sub1, :action => show) => http://sub1.domain.com/show I also tried using Lighttpd''s mod_rewrite, but can''t get it to work either. When using the following config, rails routing cannot find route, essentially the rewritten URL is not given to rails. For example, when I request: http://sub1.domain.com:3000/show, Rails outputs the following: no route found to match "/show" with {:domain=>"domain.com", :request_uri=>"/show", :protocol=>"http://", :accept s=>"text/html,text/plain,text/sgml,video/mpeg,image/jpeg,image/tiff,image/x-rgb,image/png,image/x-xbitmap,imag e/x-xbm,image/gif,application/postscript,*/*", :remote_ip=>"10.0.9.36", :method=>:get, :content_type=>nil, :po rt=>3000, :subdomain=>"sub1"} Any pointers will be greatly appreciated. Here is the relevant section from config/lighttpd.conf: $HTTP["host"] =~ "^(.+)\.domain\.com$" { fastcgi.server = (".fcgi" => ( "localhost" => ( "min-procs" => 1, "max-procs" => 1, "socket" => CWD + "/tmp/sockets/fcgi.socket", "bin-path" => CWD + "/public/dispatch.fcgi", "bin-environment" => ( "RAILS_ENV" => "development" ) ) )) url.rewrite-once = ( "^(.*)$" => "/%1/$1" ) } -pachl --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---