Mass 301 redirects in Rails 3

别来无恙 提交于 2019-12-13 19:57:59

问题


We've built up thousands of product urls while using Magento as our cart application and these URLs are not at all intuitive or that SEO friendly, despite having built up our search rankings on them.

We are transitioning to Rails 3 (with Spree as our cart) and would like to clean up our URLs. I'm wondering what's the cleanest way to handle potentially thousands of 301 redirects in Rails? Hard coding that many in routes.rb does not seem sane.

Possibly pertinent info:

We're tied to using Heroku for at least the next few months.


回答1:


The best way to do this would be with a route glob. In routes.rb:

match 'products/*product_url' => 'products#redirect_to_real_product'

As long as this match is underneath all your other product matching, it'll connect to ProductsController#redirect_to_real_product with a helpful param[:product_url] that you can perform scanning and lookup on to redirect the user to the correct product.



来源:https://stackoverflow.com/questions/9402977/mass-301-redirects-in-rails-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!