Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何重定向rails中不存在的路由_Ruby On Rails_Ruby_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 如何重定向rails中不存在的路由

Ruby on rails 如何重定向rails中不存在的路由,ruby-on-rails,ruby,ruby-on-rails-3,Ruby On Rails,Ruby,Ruby On Rails 3,我已经从一个页面排名很好的老网站切换到RubyOnRails 当然现在所有的链接都断了。当用户通过谷歌链接访问我的网站时,他将获得: Routing Error No route matches [GET] "/SOME_WRONG/URL/WITH/PARAMETERS" 在出现这样的错误时,将用户重定向到我的根url的最佳方法是什么 我要把代码放在哪里 .htaccess? application_controller? application.rb? routes.rb? 非常感谢您

我已经从一个页面排名很好的老网站切换到RubyOnRails

当然现在所有的链接都断了。当用户通过谷歌链接访问我的网站时,他将获得:

Routing Error

No route matches [GET] "/SOME_WRONG/URL/WITH/PARAMETERS"
在出现这样的错误时,将用户重定向到我的根url的最佳方法是什么

我要把代码放在哪里

.htaccess?
application_controller?
application.rb?
routes.rb?

非常感谢您:-)

在config/routes.rb的最底部,添加一个通配符路由,用于重定向:

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

现在,任何未知的路由最终都将被此规则捕获并重定向到主页。

研究路由全球化,所有未识别的路由将重定向回rails应用程序的主页


您是否在开发模式下运行live站点?生产应该提供404文件。