Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.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 如何将以“.html”结尾的所有内容重新路由到根路由(仅通过更改routes.rb)?_Ruby On Rails_Routing - Fatal编程技术网

Ruby on rails 如何将以“.html”结尾的所有内容重新路由到根路由(仅通过更改routes.rb)?

Ruby on rails 如何将以“.html”结尾的所有内容重新路由到根路由(仅通过更改routes.rb)?,ruby-on-rails,routing,Ruby On Rails,Routing,我在一个遗留静态html站点的URL上有一堆过期内容,所有内容都以.html结尾: example.com/a.html example.com/b.html 而不是显示一个Rails错误页面,该页面显示: Routing Error No route matches "/a.html" with {:method=>:get} 我想将以.html结尾的所有内容重新路由到主页(根路由): 是否可以仅通过更改路由定义来执行此操作,或者是否有必要执行此操作?您可以在config/route

我在一个遗留静态html站点的URL上有一堆过期内容,所有内容都以
.html
结尾:

example.com/a.html
example.com/b.html
而不是显示一个Rails错误页面,该页面显示:

Routing Error
No route matches "/a.html" with {:method=>:get}
我想将以
.html
结尾的所有内容重新路由到主页(根路由):


是否可以仅通过更改路由定义来执行此操作,或者是否有必要执行此操作?

您可以在config/routes.rb中执行以下操作:

map.connect ':pagename.html', :controller => 'home', :action => 'index'

有关此类型路由的更多信息,请参阅。

您可以在config/routes.rb中执行以下操作:

map.connect ':pagename.html', :controller => 'home', :action => 'index'
有关此路线样式的详细信息,请参见