Hi all. I’m moving our site from eg /staging/ to
simply be
/<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
/staging/foos/123/edit
it will send them to
/foos/123/edit
Is this something i can do in routes.rb? 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
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.
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
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.
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.