Rails: redirect all unknown routes to root_url

后端 未结 5 1617
粉色の甜心
粉色の甜心 2020-11-30 23:02

Whenever a user hits the wrong page, rails shows 404.html from the public folder. However, I\'d like just to redirect the browser to the root page, without showing anything.

5条回答
  •  误落风尘
    2020-11-30 23:32

    If your project is powered by rails 3, add simply this line to your routes.rb

    match '*path' => redirect('/')
    

    Edit: If you're on Rails 4 or 5

    match '*path' => redirect('/'), via: :get
    

    or

    get '*path' => redirect('/')
    

提交回复
热议问题