Rails 3 中的 Mass 301 重定向 [英] Mass 301 redirects in Rails 3

查看:61
本文介绍了Rails 3 中的 Mass 301 重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 Magento 作为我们的购物车应用程序时,我们已经建立了数千个产品网址,尽管我们在这些网址上建立了搜索排名,但这些网址根本不直观或对 SEO 不友好.

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.

我们正在过渡到 Rails 3(将 Spree 作为我们的购物车)并希望清理我们的 URL.我想知道在 Rails 中处理潜在的数千个 301 重定向的最干净的方法是什么?route.rb 中的许多硬编码似乎并不合理.

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.

可能的相关信息:

至少在接下来的几个月里,我们必须使用 Heroku.

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

推荐答案

最好的方法是使用 路由全局.在routes.rb:

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

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

只要此匹配项位于您所有其他产品匹配项的下方,它就会连接到 ProductsController#redirect_to_real_product 并提供一个有用的参数 [:product_url],您可以对其执行扫描和查找以将用户重定向到正确的产品.

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.

这篇关于Rails 3 中的 Mass 301 重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆