Redirect 301 on changed root name not working

franckandbeans

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"?

franckandbeans

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] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

htaccess 301 Redirect Wildcard for New Base Domain Name

분류에서Dev

301 .htacess redirect issue

분류에서Dev

Redirect from the domain with www to the root domain - working but not completely properly

분류에서Dev

301 redirect for all get request

분류에서Dev

301 Redirect a folder to a single page

분류에서Dev

htaccess 301 redirect -- remove a string

분류에서Dev

htaccess 301 redirect — remove a path

분류에서Dev

301 Redirect to a 302 Redirect (SEO implications)

분류에서Dev

Changed my user directory name in /Users without being root and permissions are messed up

분류에서Dev

Redirect query string to root

분류에서Dev

301 redirect complete url to different extension, BUT with exceptions

분류에서Dev

Redirect 301 in htaccess changes the url encoding

분류에서Dev

HTACCESS 301 redirect issue with strange url variables

분류에서Dev

htaccess redirect 301 https www to non www

분류에서Dev

URL redirect not working with .htaccess not working

분류에서Dev

Django redirect() not working

분류에서Dev

jquery redirect on keydown is not working

분류에서Dev

Codeigniter: Redirect not working

분류에서Dev

Change root name in ubuntu

분류에서Dev

Node.js: 301 redirect non-www without express

분류에서Dev

.htaccess 500 internal server error when adding simple 301 redirect

분류에서Dev

how to do 301 redirect of the same URL with a difference in hypen

분류에서Dev

Spring + Tiles. How to return 301 redirect (instead of 302) in Controller

분류에서Dev

Htaccess Redirect only directory root to new page

분류에서Dev

AngularJS SEO htaccess: redirect root domain to snapshot

분류에서Dev

Primefaces comondButton redirect stopped working

분류에서Dev

To get the url name and redirect in jQuery

분류에서Dev

Xml answer : root name is not known

분류에서Dev

Changed root password on my server, now can't login anymore

Related 관련 기사

  1. 1

    htaccess 301 Redirect Wildcard for New Base Domain Name

  2. 2

    301 .htacess redirect issue

  3. 3

    Redirect from the domain with www to the root domain - working but not completely properly

  4. 4

    301 redirect for all get request

  5. 5

    301 Redirect a folder to a single page

  6. 6

    htaccess 301 redirect -- remove a string

  7. 7

    htaccess 301 redirect — remove a path

  8. 8

    301 Redirect to a 302 Redirect (SEO implications)

  9. 9

    Changed my user directory name in /Users without being root and permissions are messed up

  10. 10

    Redirect query string to root

  11. 11

    301 redirect complete url to different extension, BUT with exceptions

  12. 12

    Redirect 301 in htaccess changes the url encoding

  13. 13

    HTACCESS 301 redirect issue with strange url variables

  14. 14

    htaccess redirect 301 https www to non www

  15. 15

    URL redirect not working with .htaccess not working

  16. 16

    Django redirect() not working

  17. 17

    jquery redirect on keydown is not working

  18. 18

    Codeigniter: Redirect not working

  19. 19

    Change root name in ubuntu

  20. 20

    Node.js: 301 redirect non-www without express

  21. 21

    .htaccess 500 internal server error when adding simple 301 redirect

  22. 22

    how to do 301 redirect of the same URL with a difference in hypen

  23. 23

    Spring + Tiles. How to return 301 redirect (instead of 302) in Controller

  24. 24

    Htaccess Redirect only directory root to new page

  25. 25

    AngularJS SEO htaccess: redirect root domain to snapshot

  26. 26

    Primefaces comondButton redirect stopped working

  27. 27

    To get the url name and redirect in jQuery

  28. 28

    Xml answer : root name is not known

  29. 29

    Changed root password on my server, now can't login anymore

뜨겁다태그

보관