我的目标是当用户请求root(AND ONLY ROOT,其他页面工作正常)时,例如:
http://domain.com/////
http://domain.com//////////////
http://domain.com//
应用 301重定向用户只能更正:
http://domain.com/
我正在使用 Webrick,机架重写宝石并计划在 Heroku 上托管它。 请记住,我是Rails中的新手。
更新 ======
Rails: redirect all unknown routes to root_url - 这是完全不同的问题。他们只是将所有未知主机重定向到root。我有404正常工作。
我的问题是,任何数量的斜杠都可以作为主页使用,而URL则包含所有这些斜杠。我正在为SEO做这件事来摆脱主页的重复。我希望它像这里一样工作:http://netpeak.ua(尝试" netpeak.ua ////////",您将被重定向到" netpeak.ua" )。
更新2 - 添加routes.rb的内容 ======
Rails.application.routes.draw do
resources :questions
resources :feedbacks
devise_for :users
get '' => 'public#index'
get '/agency' => 'public#about'
get '/contact' => 'public#contact'
get '/uslugi' => 'services#index'
get '/portfolio' => 'projects#index'
get '/uslugi/:id' => 'services#show'
get '/portfolio/:id' => 'projects#show'
resources :articles, param: :id
resources :settings, as: 'home' #home so it doesn't go to another page
namespace :admin do
resources :articles, :users, :projects, :services, :feedbacks, :questions
get '' => 'projects#index'
get 'contact' => 'settings#contact'
get 'feedback' => 'settings#feedback'
get 'fininfo' => 'settings#fininfo'
get 'calls' => 'settings#calls'
get 'orders' => 'settings#orders'
get 'letters' => 'settings#letters'
get 'allquestions' => 'settings#allquestions'
get 'projectsettings' => 'settings#projectsettings'
get 'servicessettings' => 'settings#servicessettings'
get 'aboutsettings' => 'settings#aboutsettings'
get 'startpagesettings' => 'settings#startpagesettings'
patch 'contact' => 'settings#update'
patch 'feedback' => 'settings#update'
patch 'fininfo' => 'settings#update'
patch 'projectsettings' => 'settings#update'
patch 'servicessettings' => 'settings#update'
patch 'aboutsettings' => 'settings#update'
patch 'startpagesettings' => 'settings#update'
end
end