[英]How to redirect url /example to /example/ in Ruby on Rails ?
I has asked this earlier How to solve Rails duplicate url (canonical) issue ? 我之前已经问过这个问题, 如何解决Rails重复url(规范)问题? redirect /example to /example/ and was told to use
将/ example重定向到/ example /并被告知要使用
get '/page' => redirect('/page/')
but I have hundreds of such page and this is not a very scalable solution. 但是我有数百个这样的页面,这不是一个非常可扩展的解决方案。 In apache I uses .htaccess since I am using phusion passenger, so do we have some solution ?
在Apache中,我使用.htaccess,因为我使用的是乘载乘客,那么我们有解决方案吗? or any routes.rb way to do it ?
或任何route.rb的方法吗?
You can have all your urls ends with a trailing slash by setting :trailing_slash
to true in your application.rb 您可以在应用程序中将
:trailing_slash
设置为true,以使所有网址都以斜杠:trailing_slash
config.action_controller.default_url_options = { :trailing_slash => true }
A related post can be found here: How to make Rails do not ignore trailing slashes in the routes? 在此处可以找到相关的文章: 如何使Rails不忽略路线中的尾部斜杠?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.