0

我的应用中有这样的链接

http://localhost:3000/lv/manufacturer_products?manufacturer=Komptech

http://localhost:3000/en/products?category=Shredders

但是我的朋友说这些链接对 SEO 不友好,我必须更改它们,以

http://localhost:3000/en/manufacturer_products/Komptech

或与此类似

http://localhost:3000/en/products/category/Shredders

但是,在没有任何宝石帮助的情况下,我如何才能真正改变链接的结构呢?使用路线?

谢谢

4

3 回答 3

1

请参阅名称空间的文档以及有关 SO 的此答案。

你甚至可以只做命名路线。像这样的东西:

resources :products do
  resources :manufacturers
end

这对于 index 操作manufacturers将返回:

product_manufacturers GET    /products/:product_id/manufacturers(.:format)          manufacturers#index

然后你可以写在 routes.rb

match '/:id/products/:name', 
     :to => 'manufacturers#index', :as => :manufacturers   

当你调用它时

<%= link_to @manufacturer.name, manufacturers_path({id: @manufacturer.product_id, name: @manufacturer.name}) %>

这将呈现http://localhost:3000/x/products/Komptech

于 2013-08-29T08:29:46.207 回答
1

Ryan Bates 有一个关于这个的 railscast,我总是遵循这个,

http://railscasts.com/episodes/314-pretty-urls-with-friendlyid

于 2013-08-29T08:18:42.067 回答
0

我不能限制我分享这个......一旦我得到了一个很好的帮助来优化我的网站的 SEO

查看链接

http://complitech.net/seo-basics-high-benifit-for-ruby-on-rails-developer/

看看第三点得到了你对 url 的答案

3) 改进你的 URL 结构

通常在旧式中,url 是非结构化的,而不是目录明智的,所以让你的 URL 是结构化的。

例子:

www.herrybaseballcards.com/images/baseball/top-10-baseballcards.html

所以在路线

match '/:foldername/:products/:name', :to => 'products#index', :as => :products

所以忽略基于查询的 URL 结构

于 2013-08-29T08:22:37.237 回答