开发者

How do I 301 redirect these route changes?

I have a couple routes like this:

  match ':category/:brand/:permalink' => 'products#show', :as => :public_product
  match 'stoves' => 'home#stoves', :as =>开发者_JAVA百科 :stoves

I changed them to this:

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

I changed the category record titled stoves to wood_stoves.

Can I add a route redirect that allows for wildcards that would change anything like domain.com/stoves or domain.com/stoves/morso/8140-contemporary to domain.com/wood_stoves or domain.com/wood_stoves/morso/8140-contemporary, respectively? Or should I put this in my apache virtualhost config block?


Let your route.rb to be like this:

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

In your Home Controller:

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


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

This is enough i think.

If you are so particular about to change the name of the action to wood_stoves then i think you need to do Surya's solution

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜