Ad

How To Make A Page Accessible By Two Urls For Seo Purposes?

- 1 answer

We currently have a page that has this url: /tires?product_subtype=8. The page content is a tires list filtered by a specific product subtype. For SEO purposes, we also need the page to be accessible via this url: /lawn-and-garden.

Is there an easy way to do this? We're using Ruby on Rails framework and Nginx.

We will be doing this on lots of pages:

/tires?product_subtype=1 - /industrial-tires
/tires?product_subtype=2 - /commercial-tires
etc...
Ad

Answer

If both the routes are performing the same task then route them to the same controller#action in config/routes.rb.

For example:

get 'tires', to: 'welcome#index'
get 'lawn-and-garden', to: 'welcome#index'

UPDATE:

If I understand you right, then you would like the page to be accessible by both routes /tires?product_subtype=1 as well as /industrial-tires(without query param). We have done something similar on one of our projects, we call these pretty url's as landing pages. I can think of two options to implement these landing pages:

  • If you have a fixed number of very few landing pages:

    create an action for each of them which renders corresponding subtype view.

    def industrial_tires
      ## render view filtered for product_subtype = 1
    end
    
    def commercial_tires
      ## render view filtered for product_subtype = 2
    end
    ## .... so on
    
  • If you have many/ variable number of landing pages:

    you will have to create a low priority catch all route and within the mapped action conditionally render specific view based on the slug.

    get '*path', to: 'tires#landing_page'  ## in routes.rb at the end of the file
    
    def landing_page
      ## "path" would be equal to industrial-tires or commercial-tires, etc.
      ## conditionally specify view filtered for product_subtype based on path value
    end 
    
Ad
source: stackoverflow.com
Ad