Creating a rails route to an external URL

I know this is old, so in case someone else needs this for rails 4:

get "/blog" => redirect("http://example.com/blog")

Use get instead of Match in Rails 4, otherwise you'll get a Runtime error


Depends on the Rails version you are using.

Rails 3

# in routes.rb
match "/blog" => redirect("http://example.com/blog"), :as => :blog

Rails 2

# in routes.rb
map.blog '/blog',
  :controller => "a_helper_controller",
  :action => "redirect_to_blog"

# in a_helper_controller.rb
def redirect_to_blog
  redirect_to "http://example.com/blog"
end

For Rails 5:

get '/stories', to: redirect('/articles')
get '/stories', to: redirect('http://google.com')

Rails Guide source page