如何使一个页面可以被两个 url 访问以用于 seo 目的?

How to make a page accessible by two urls for seo purposes?

我们当前有一个页面包含此 url:/tires?product_subtype=8。页面内容是按特定产品子类型过滤的轮胎列表。出于 SEO 目的,我们还需要可以通过此 url: /lawn-and-garden 访问该页面。

有没有简单的方法来做到这一点?我们在 Rails 框架和 Nginx 上使用 Ruby。

我们将在很多页面上这样做:

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

如果两条路由执行相同的任务,则将它们路由到 config/routes.rb 中的相同 controller#action

例如:

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

更新:

如果我没理解错,那么您希望页面可以通过 /tires?product_subtype=1/industrial-tires(没有查询参数)两种途径访问。我们在我们的一个项目中做了类似的事情,我们称这些漂亮的 url 作为登陆页面。我可以想到两种实现这些着陆页的选项:

  • 如果您的目标网页数量固定且很少:

    为它们中的每一个创建一个呈现相应子类型视图的操作。

    def industrial_tires
      ## render view filtered for product_subtype = 1
    end
    
    def commercial_tires
      ## render view filtered for product_subtype = 2
    end
    ## .... so on
    
  • 如果您有很多/可变数量的着陆页:

    您将必须创建一个低优先级的 catch all 路由,并在映射的操作中根据 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 
    

我建议您将各种类别路由到单个 CategoriesController 并为每个类别创建一个操作。

/routes.rb

...
get 'lawn-and-garden', to: 'categories#lawn_and_garden'
get 'industrial-tires', to: 'categories#industrial_tires'
...

/categories_controller.rb

def lawn_and_garden
  params[:product_subtype] = '8'
  @tires = YourTireFilter.search(params)
  render 'tires/index'
end

def industrial_tires
  params[:product_subtype] = '1'
  @tires = YourTireFilter.search(params)
  render 'tires/index'
end

对其他网址重复此操作。