-1

出于 SEO 目的,我希望 root_path 为“”。换句话说,我希望规范主页 URL 是 domain.com 而不是 domain.com/。我试图设置

# routes.rb
get '' => 'home#index', as: :root

# rack_rewrite.rb
Rails.application.config.middleware.insert_before(Rack::Sendfile, Rack::Rewrite) do
  r301   %r{^/$}, ''
end

但这不起作用。 rake routes仍然显示:

root GET    /                home#index
4

2 回答 2

1
#config/routes.rb
root "home#index"

http://guides.rubyonrails.org/routing.html#using-root

于 2014-09-21T10:08:45.107 回答
0

在您的路由文件中,您可以添加 home -> 控制器和索引 -> 方法

Rails.application.routes.draw do
   root to: "home#index"
   # more routes
end
于 2021-01-11T16:20:54.503 回答