2009-08-19 77 views
0

我在URL的一堆過期的內容都從傳統的靜態HTML網站.html結束:如何將所有以`.html`結尾的內容重新路由到根路由(只更改routes.rb)?

example.com/a.html 
example.com/b.html 

而不是顯示一個Rails的錯誤頁面,上面寫着:

Routing Error 
No route matches "/a.html" with {:method=>:get} 

我想重新路由在.html主頁(根路徑)結束全部內容:

map.root :controller => 'home', :action => 'index' 

是否有可能通過只更改路線定義來做到這一點,或者是否需要define a catch-all route

回答

3

你可以做類似下面,在配置/ routes.rb中:

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

對這種風格路線的更多信息,請參見Regular Routes section of the Rails Routing Guide

+0

謝謝! – apple 2009-08-19 00:51:50

相關問題