LoginSignup
35
33

More than 5 years have passed since last update.

特定のURLをRailsのconfig/route.rbでリダイレクトさせる方法

Last updated at Posted at 2014-07-12

特定のURLにリダイレクトさせたい時の方法をご紹介。

moss.com/moss1/interview/23455 できたアクセスを
moss.com/moss2/interview/23455 にリダイレクトさせたい場合。

config/routes.rb
Moss::Application.routes.draw do

root "home#index", as: :root
get  "/moss1/interview/:id" => redirect("/moss2/interview/%{id}")
get  "/moss2/interview/:id", to: "interview#show"
........

end

と書くだけ。moss.com/moss1/interview/:idにユーザーが訪れたときに、moss.com/moss2/interview/:idに自動でリダイレクトされます。

35
33
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
35
33