2012-05-28 33 views
4

我正在構建一個博客平臺(RoR),並計劃使用以下格式,有什麼缺點?爲博客平臺推薦的Url格式

# All Users: 
http://www.example.com/users/ 

# A single user (123 is the user id, id is needed for uniqueness) 
http://www.example.com/users/123/peter 

# All Categories 
http://www.example.com/categories/ 

# A single category listing (123 is the cat id, note: job is singular) 
http://www.example.com/categories/123/job 

# All Tags 
http://www.example.com/tags/ 

# A single tag listing (123 is the tag id, note: car is singular) 
http://www.example.com/tags/123/car 

# A single post 
http://www.example.com/posts/123/my-title 

任何建議或改善的地方?

謝謝。

回答

5

這一切都取決於你的應用程序中最重要的課題。假設應用程序的主題是帖子,則帖子的URL必須「靠近」根網址。

因此,他們應該是這樣的:

# A single post 
http://www.example.com/123-my-post-title 

# All Users: 
http://www.example.com/users/ 

# A single user (supposing the username must be unique) 
http://www.example.com/users/peter 

# All Categories 
http://www.example.com/categories/ 

# A single category listing (supposing the category name must be unique) 
http://www.example.com/categories/job 

# All Tags 
http://www.example.com/tags/ 

# A single tag listing (supposing tags must be unique) 
http://www.example.com/tags/car 

這涉及2發生在你的路線:

1)入門您網址擺脫 「/職位/」。要做到這一點,你可以聲明你的資源是這樣的:

resources :posts, :path => "/" 

2)中的所有網址擺脫ID,除了崗位#秀(來自不同用戶的帖子可能具有相同的標題,有時,如果沒有,你在這些情況下也可以省略ID)。

要做到這一點應該重寫你的模型to_param方法是這樣的:

class Post < ActiveRecord::Base 
     def to_param 
     "{id}-#{title.parameterize}" 
     end 
    end 

或使用friendly_id gem如果你正在尋找首要to_param困難。

1

我遇到了同樣的問題,我遇到了一個偉大的寶石,使您的搜索引擎優化和人性化:friendly_id

下面是一個很棒的截屏:Pretty URLs with FriendlyId

我不打算在這裏詳細討論,因爲我相信你會在文檔或截屏視圖中找到你需要的一切。快樂的SEO!

0

因爲(我認爲)的用戶有獨特的暱稱,網址可以更簡單:

http://www.example.com/users/peter 

同樣可以適用於標籤和類別。您不要忘記根據參數化來檢查名稱的唯一性。

這也將有助於避免類似名稱的對象的重複:

"peter the great".parameterize => "peter-the-great" 
"Peter-THE-Great".parameterize => "peter-the-great" 

而這僅僅是我的意見,在大多數情況下使用的邏輯與獨特的id-nameid/name(看這個問題的網址: ))。

0

我會承認,我對SEO的知識並沒有像StackOverFlow上一些更有經驗的人那麼深遠。但是我知道,當涉及到URL時,通常應用'較短和可讀性更好的'規則。因此,在網址中使用ID是一個很大的挫折,可能會對谷歌或其他搜索引擎對您的SEO分數產生負面影響。

您可以從谷歌免費的SEO入門指南中的閱讀相當升技它至極,你可以找到PDF瀏覽:http://static.googleusercontent.com/external_content/untrusted_dlcp/www.google.com/nl//webmasters/docs/search-engine-optimization-starter-guide.pdf

有關的URL的部分是這個PDF第8頁。

至於你的應用程序,避免使用ID的方法是爲你的用戶使用暱稱。你會發現這在整個網絡上的論壇上通常使用。這些暱稱始終有一個唯一的限制,確保始終只有一個用戶使用該暱稱。這也使得您可以爲這些暱稱創建限制,例如禁止使用暱稱中的數字,這樣人們就無法創建像John123這樣的暱稱。

你到底想用這樣的URL來結束:

http://www.example.com/users/uniquenickname 

同樣的想法也適用於使用類別和標籤。

當涉及到帖子你有2個選項真正取決於你的意思是一個職位。 如果通過發佈,你只是指一個博客條目,那麼你可以簡單地使用條目的類別,用戶和標題的組合來創建一個獨特的網址。

例如:http://www.example.com/category/uniquenickname/entrytitle

如果您換貨的帖子在博客上的條目作出評論,然後使用你上面提供的網址將被罰款,但你可能要在robots.txt中添加了履帶不允許對這些網址進行索引。 這背後的原因是,你往往有垃圾郵件機器人圍繞博客張貼增加廣告和鏈接到你絕對不希望與之相關聯的網頁,並且你想阻止抓取工具將這些鏈接編入索引,這可能會產生相當負面的影響你的SEO分數。

我希望這有助於:)

+0

我聽到很多聲稱身份證號碼降低SEO分數。數字+人類可讀的字符串的確如此嗎?所有關於SEO評分如何工作的說法都沒有鏈接,因爲文檔是令人失望的。 –

-1

我非常自私和自豪,所以儘量使我的網站難以抓取:P,儘量不要在您的網址上使用數字標識。這使得整個網站的搜索變得非常簡單。 只要有可能就製作唯一的網址。

如果你的文章的標題是唯一的,那麼把它作爲id並在你的url中使用它。

如果您的用戶名是唯一的,則將其用作ID。例如:

#所有用戶: http://www.example.com/users/

# A single user 
http://www.example.com/users/peter 

# All Categories 
http://www.example.com/categories/ 

# A single category 
http://www.example.com/categories/job 

# All Tags 
http://www.example.com/tags/ 

# A single tag listing (They are unique, each one should be a key itself) 
http://www.example.com/tags/car 

# A single post 
http://www.example.com/posts/date-here/my-unique-title 

谷歌喜歡有至少一個位數字的網址。將日期添加到新聞網址是一種很好的做法,它也會增加SEO價值。像這樣http://www.example.com/posts/2012/06/06/my-unique-title

+0

如果你很自私,爲什麼你要和互聯網分享你的內容? 'robots.txt' – 0xcaff