Ruby on Rails - 将参数传递到 routes.rb 中的 301 重定向 [英] Ruby on Rails - passing params into 301 redirect in routes.rb
本文介绍了Ruby on Rails - 将参数传递到 routes.rb 中的 301 重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想更改 routes.rb 中现有的游戏"路由,但由于 SEO,我还需要为旧链接设置 301 重定向.
I want to change my existing 'game' routing inside routes.rb, but because of SEO I need also to setup 301 redirect for old links.
我的旧路由:
match 'games/:permalink/:id/(:page)' => 'games#show'
新路由:
match 'gierki/:permalink/(:page)' => 'games#show'
这是我尝试做的重定向:
Here is redirection which I tried to to do:
match 'games/:permalink/:id/(:page)' => redirect {|params| "/gierki/#{params[:permalink]}" + params[:page].nil? ? "" : "/#{params[:page]}" }
以上重定向不起作用,这是一个错误:
Above redirect is not working, here is an error:
wrong number of arguments (1 for 2)
推荐答案
尝试这样做:
match 'games/:permalink/:id/(:page)' => redirect {|params,request| "/gierki/#{params[:permalink]}" + params[:page].nil? ? "" : "/#{params[:page]}" }
看看它是否有效.
这篇关于Ruby on Rails - 将参数传递到 routes.rb 中的 301 重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文