I am trying to implement a 301 redirect in my roots in order to remove duplicate pages. However i have also changed the root path name from "products" to "produits". Here are my routes:
resources :products, path: "produits" do
resources :product_variants, only: [:new, :create, :edit, :update]
collection do
get :unavailable_products
end
end
get '/products', to: redirect(path: '/produits')
get '/products/:id', to: redirect('/produits/%{id}')
and here are my rails routes:
products GET /products(.:format) redirect(301, path: /produits)
GET /products/:id(.:format) redirect(301, /produits/%{id})
product_product_variants POST /produits/:product_id/product_variants(.:format) product_variants#create
new_product_product_variant GET /produits/:product_id/product_variants/new(.:format) product_variants#new
edit_product_product_variant GET /produits/:product_id/product_variants/:id/edit(.:format) product_variants#edit
product_product_variant PATCH /produits/:product_id/product_variants/:id(.:format) product_variants#update
PUT /produits/:product_id/product_variants/:id(.:format) product_variants#update
unavailable_products_products GET /produits/unavailable_products(.:format) products#unavailable_products
GET /produits(.:format) products#index
POST /produits(.:format) products#create
new_product GET /produits/new(.:format) products#new
edit_product GET /produits/:id/edit(.:format) products#edit
product GET /produits/:id(.:format) products#show
PATCH /produits/:id(.:format) products#update
PUT /produits/:id(.:format) products#update
DELETE /produits/:id(.:format) products#destroy
The problem is that i have tried changing the "get '/products', to: redirect(path: '/produits')" to "match" but it gives me the following error:
You should not use the `match` method in your router without specifying an HTTP method. If you want to expose your action to both GET and POST, add `via: [:get, :post]` option. If you want to expose your action to GET, use `get` in the router: Instead of: match "controller#action" Do: get "controller#action"
How to I redirect all product pages to "produits" and not have a route for "products"?
I found the issue, it was due to the route order.
The "get '/products', to: redirect(path: '/produits')" and others gets have to be AFTER the resources routes.
The order matters!
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다