出于 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