如何301重定向这些路线更改?

时间:2011-04-29 04:32:09

标签: ruby-on-rails apache ruby-on-rails-3 routing

我有几条这样的路线:

  match ':category/:brand/:permalink' => 'products#show', :as => :public_product
  match 'stoves' => 'home#stoves', :as => :stoves

我将它们改为:

  match ':category/:brand/:permalink' => 'products#show', :as => :public_product
  match 'wood_stoves' => 'home#wood_stoves', :as => :stoves

我将标题为stoves的类别记录更改为wood_stoves

我可以添加路由重定向,允许分别将domain.com/stovesdomain.com/stoves/morso/8140-contemporary更改为domain.com/wood_stovesdomain.com/wood_stoves/morso/8140-contemporary的通配符吗?或者我应该把它放在我的apache virtualhost配置块中?

1 个答案:

答案 0 :(得分:0)

让你的route.rb像这样:

match ':category/:brand/:permalink' => 'products#show', :as => :public_product
match 'stoves' => 'home#stoves', :as => :old_stoves # anything else except stoves
match 'wood_stoves' => 'home#wood_stoves', :as => :stoves

在您的家庭控制器中:

def stove
  redirect_to stoves_path(# Use parameters here when a user hits a link like domain.com/stoves or domain.com/stoves/morso/8140-contemporary)
end
def wood_stoves
  # your code here..
end