【问题标题】:How to reroute all content that ends in `.html` to the root route (by only changing routes.rb)?如何将所有以`.html`结尾的内容重新路由到根路由(仅更改routes.rb)?
【发布时间】:2009-08-19 00:24:40
【问题描述】:

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

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

【问题讨论】:

    标签: ruby-on-rails routing


    【解决方案1】:

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

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

    有关这种路线的更多信息,请参阅Regular Routes section of the Rails Routing Guide

    【讨论】:

      猜你喜欢
      • 2023-03-18
      • 2018-05-07
      • 2013-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-06
      • 2021-10-14
      • 1970-01-01
      相关资源
      最近更新 更多