Rails: redirect all unknown routes to root_url

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

match '*path' => redirect("https://stackoverflow.com/")

Edit: If you’re on Rails 4 or 5

match '*path' => redirect("https://stackoverflow.com/"), via: :get

or

get '*path' => redirect("https://stackoverflow.com/")

Leave a Comment