2017-05-03 14 views
1

我们目前有一个网页有这个网址:/tires?product_subtype=8。页面内容是按特定产品子类型过滤的轮胎列表。对于搜索引擎优化的目的,我们还需要通过以下网址访问该页面:/lawn-and-garden如何让页面可以通过两个URL访问seo目的?

有没有简单的方法来做到这一点?我们正在使用Ruby on Rails框架和Nginx。如果两个路由在config/routes.rb执行相同的任务,然后将它们路由到同一controller#action

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

我想你需要在控制器中测试'params [:product_subtype]'并重定向到合适的页面。 – moveson

+0

@moveson问题是我们还需要通过其原始网址访问网页。我们不想将它们重定向到其他网址。例如:如果用户访问'/ tires?product_subtype = 8',则url将保持不变。如果用户访问'/ lawn-and-garden',则URL也将保持不变。没有重定向会发生。 –

+0

在这种情况下,您只需要每个控制器呈现相同的视图。 – moveson

回答

1

我们将在大量的网页来这样做。

例如:

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

UPDATE:

如果我理解你的权利,那么你会喜欢这个页面是由两条路线/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 
    
  • 如果您有许多/可变数量的着陆页:

    ,你必须创建一个低优先级捕获所有路线和映射操作中有条件地呈现基于蛞蝓特定视图。

    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 
    
+0

我认为OP要根据'product_subtype'参数的不同重定向。 – moveson

+0

这是行不通的,因为我们必须考虑'product_subtype'查询字符串参数。 –

+0

@ JohnKevinM.Basco所以你的意思是说你不想将相同的查询字符串参数传递给第二条路线,但有多条路线,比如'''相当于'/ tires?product_subtype = 1'的'industrial-trial',''commercial-tires '相当于''/ tires?product_subtype = 2'等等。? –

1

我想您将自己的各类建议单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 

重复其他网址。

相关问题