简体   繁体   English

如何在Ruby on Rails中将url / example重定向到/ example /?

[英]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.

相关问题 Ruby on Rails Cron作业示例 - Ruby on Rails Cron Job Example 如何在Ruby on Rails中通过路由重定向URL - How to redirect URL by routes in Ruby on Rails 如何从Rails上的ruby返回JSON入门示例 - How to return JSON from the ruby on rails getting started example 如何在Rails 2.3.3中从example.com/products重定向到www.example.com/products - How to redirect to www.example.com/products from example.com/products in Rails 2.3.3 Rails-如何从http://example.com重定向到https://www.example.com - Rails - How to Redirect from http://example.com to https://www.example.com 在Ruby on Rails路由中,可以是www.example.com/…#! …总是去控制器=>'redirect'? - in Ruby on Rails routing, can it be www.example.com/ … #! … always go to controller => 'redirect'? Facebook Messenger-Ruby on Rails的节点-示例 - Facebook Messenger - Node to Ruby on Rails - Example Ruby on Rails: If Else 基于 params[:example] - Ruby on Rails: If Else based on params[:example] 红宝石,铁轨,铁轨例子我搞砸了 - ruby, rails, railscasts example I messed up 使用Ruby on Rails 5以模态方式打开显示页面,并在地址栏中更新网址,如instagram示例所示 - Opening show page in a modal with updating url in address bar as in instagram example using Ruby on Rails 5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM