2015-10-14 45 views
-1

我目前在rails应用程序中使用freindly_id gem来啃网址,并使它们看起来不错。因此,他们是#根/城市/#城市名称而不是URL#root/cities /#cityname使用301重定向来维护搜索引擎优化

我们希望将URL的cityname部分更改为其他内容,并且它看起来与更改数据库中的slug一样直接简单地阅读别的东西,然而,有人建议我们必须使用301重定向,以维持我们迄今为止获得的搜索引擎优化。

任何人都可以告诉我,如果使用slug改变网址是否有影响,从我的角度来看,这似乎并没有真正改变网址,底层的URL仍然是/城市/ 1234

+0

,这就是为什么我标记SEO –

+0

另外,如果是使用蛞蝓和维护当前交通的更好的方法,这是一个有效的问题 –

+1

我不会直接做在数据库。如果你使用friendly_ids [history](http://norman.github.io/friendly_id/file.Guide.html#History__Avoiding_404_s_When_Slugs_Change)功能,你可以在你的rails控制器中做一个重定向,如果它使用了过时的slug。 –

回答

2

我不会直接在数据库中。如果您使用friendly_ids history功能,您可以在导轨控制器中进行重定向,如果它使用的是过时的slu slu。

从文档:

before_filter :find_post 

def find_post 
    @post = Post.find params[:id] 

    # If an old id or a numeric id was used to find the record, then 
    # the request path will not match the post_path, and we should do 
    # a 301 redirect that uses the current friendly id. 
    if request.path != post_path(@post) 
    return redirect_to @post, :status => :moved_permanently 
    end 
end 
相关问题