Remove first part of path, if = a particular string?

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

Hi Max,

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 :wink:

Best regards,
Bill

Bill Walton wrote:

Easily, with named routes.

Thanks Bill - would you mind explaining your easy named routes solution?
:slight_smile:

Hi Max,

Bill Walton wrote:

Easily, with named routes.

Thanks Bill - would you mind explaining your easy named routes solution?
:slight_smile:

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

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