Railsのconfig/routes.rbでリダイレクトさせる(ステータスコードを指定する)

Railsroutes.rbの中のルーティング設定でリダイレクトさせる方法です。

普通にリダイレクトさせる。

get '/hoge', to: redirect('/hogehoge')

httpステータスコードを指定してリダイレクトさせる。

get '/hoge', to: redirect('/hogehoge', status: 301)

URLにパラメータを含む場合

get '/hoges/:id', to: redirect('/hogehoges/%{id}', status: 301)

パラメータに対して正規表現で有効な値を指定する

get '/hoges/:id', to: redirect('/hogehoges/%{id}', status: 301), constraints: { id: /\d/ }

Rails Routing from the Outside In — Ruby on Rails Guides Route.Constraints プロパティ (System.Web.Routing)