Hi all. I''m moving our site from eg <domain>/staging/<rest of path> to simply be <domain>/<rest_of_path>. I want to catch all the people who have bookmarked the "staging/" urls (or have them in their browser history) and redirect them to the equivalent url without "staging/". Eg if someone goes to <domain>/staging/foos/123/edit it will send them to <domain>/foos/123/edit Is this something i can do in routes.rb? Or is it better done at the server config level? thanks, max -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Bill Walton
2010-Jun-28 12:06 UTC
Re: Remove first part of path, if = a particular string?
Hi Max, On Mon, Jun 28, 2010 at 6:51 AM, Max Williams <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi all. I''m moving our site from eg <domain>/staging/<rest of path> to > simply be > <domain>/<rest_of_path>. I want to catch all the people who have > bookmarked the "staging/" urls (or have them in their browser history) > and redirect them to the equivalent url without "staging/". Eg if > someone goes to > > <domain>/staging/foos/123/edit > > it will send them to > > <domain>/foos/123/edit > > Is this something i can do in routes.rb?Easily, with named routes.> Or is it better done at the server config level?I''m pretty sure you could do it with mod_rewrite rules. And that would keep your routes.rb smaller, so ''better'' in that sense. OTOH, it''s probably a worthwhile effort to do it with routes first, just to make sure you identify any edge cases. My advice would be to make the final decision based on your Apache config experience / comfort level. Mine''s minimal ;-) Best regards, Bill -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Max Williams
2010-Jun-28 12:18 UTC
Re: Remove first part of path, if = a particular string?
Bill Walton wrote:> > Easily, with named routes. >Thanks Bill - would you mind explaining your easy named routes solution? :) -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Bill Walton
2010-Jun-28 15:02 UTC
Re: Re: Remove first part of path, if = a particular string?
Hi Max, On Mon, Jun 28, 2010 at 7:18 AM, Max Williams <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Bill Walton wrote: > >> >> Easily, with named routes. >> > > Thanks Bill - would you mind explaining your easy named routes solution? > :)Without knowing more about your Rails version and existing routes it''s a bit tough to give you ''the'' solution, but as a starting pointI''d try ''simply'' installing some new default routes. map.connect ''/staging/:controller/:action'' map.connect ''/staging/:controller/:action/:id'' map.connect ''/staging/:controller/:action/:id.:format'' At the other end of the tedium spectrum, you could put a named route with /staging added to the beginning of the url in place for each of your existing routes. Run ''rake routes'' for a list. Sorry I don''t have more time today. It''s Monday, for sure ;-). There are good online resources for routing. I''d recommend starting with http://guides.rubyonrails.org/routing.html HTH, Bill -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Max Williams
2010-Jun-28 15:08 UTC
Re: Re: Remove first part of path, if = a particular string?
Hi Bill - thanks. That had occurred to me too, but I was hoping to not have to go through and individually catch every possible route and individually redirect each one. The problem with this as well is that it lets people carry on using the staging urls, silently sending them through to the right action. What i did in the mean time, and i might stick with this, is just catch missing route exceptions in application_controller and, if they start with "staging/" just redirect users to the home page with a flash message. That way at least they get redirected to the proper home page url, from which they can start building up a more appropriate browsing history again. thanks for your help, max -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Jun-28 15:31 UTC
Re: Re: Remove first part of path, if = a particular string?
Max Williams wrote:> Hi Bill - thanks. That had occurred to me too, but I was hoping to not > have to go through and individually catch every possible route and > individually redirect each one. The problem with this as well is that > it lets people carry on using the staging urls, silently sending them > through to the right action. > > What i did in the mean time, and i might stick with this, is just catch > missing route exceptions in application_controller and, if they start > with "staging/" just redirect users to the home page with a flash > message. That way at least they get redirected to the proper home page > url, from which they can start building up a more appropriate browsing > history again.Simple: map.connect ''staging/*rest_of_path'' to some staging action In your staging action, have some logic that sets the flash and redirects to rest_of_path.> thanks for your help, maxBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.