2015-10-14 97 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 
相關問題