How to redirect non existing routes in rails

ruby, ruby-on-rails, ruby-on-rails-3

Solution

At the very bottom of config/routes.rb, add a wildcard route that redirects:

match "*missing" => redirect("/")

Now any unknown routes will finally be caught by this rule and redirected to the homepage.

Problem

I have switched from an old site with a good page rank to RubyOnRails. Of course all links are broken now. When a user visits my site via a google link he will get: ``` Routing Error No route matches [GET] "/SOME_WRONG/URL/WITH/PARAMETERS" ``` What is the best way to redirect the user on error like that to my root_url? And where I have to put this code? ``` .htaccess? application_controller? application.rb? routes.rb? ``` many many thanks in advance :-)

Original source