Possible to create this redirecting route in Rails?

Shpigford picture Shpigford · Mar 25, 2010 · Viewed 42.1k times · Source

Is it possible to do a redirect in the routes file of a Rails app?

Specifically, I'd like to forward /j/e to /javascripts/embed.js

Right now the only way I can think to do it is to create a j controller with an e method that redirects to that.

Answer

Steven Soroka picture Steven Soroka · Sep 16, 2010

In Rails 4 and 5: (thanks @dennis)

get '/stories', to: redirect('/posts')

In Rails 3, you can redirect inside the routes.rb file.

match "/posts/github" => redirect("http://github.com/rails.atom")