Giancarlo Corzo
Giancarlo Corzo

Reputation: 2006

Rails route redirect to a inner url

I've changed in my rails project the url from /tours/* to /tours/peru/. It's working fine but google already indexed the /tours/ url so I want to write a route that redirect the the URL to the new version of the URL

My code It's like this:

  resources :tours, path: '/tours/peru' do
    resources :reviews
    resources :images
    resources :quotes
  end 

  match "/tours/:id" => redirect("/tours/peru/:id")

So I'm sure who to write the redirect to make it work

Upvotes: 3

Views: 2947

Answers (2)

Gabriel Osorio
Gabriel Osorio

Reputation: 1063

If you're looking for a GET redirect, I'd propose something like:

get '/tours/:id', to: redirect('/tours/peru/%{id}')

For more ruby 1.9+ syntax. Don't mean to be too picky. :)

Upvotes: 1

Chris Salzberg
Chris Salzberg

Reputation: 27374

I think the correct syntax is:

match "/tours/:id" => redirect("/tours/peru/%{id}")

See the documentation for more info.

Upvotes: 2

Related Questions