Reputation: 10101
I am building a blog platform (RoR), and planing to use the following format, any drawback?
# 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
Any suggestion or place to improve?
Thanks.
Upvotes: 4
Views: 737
Reputation: 1345
Im very selfish and proud so try to make scraping my sites difficult :P, try not to use numeric ID's on your url's.It makes it really easy to scrape your whole site. Make unique url's whenever you can.
If your post's title is unique, then make it the id and use it in your url.
If your username is unique, then use it as the ID. For example:
# All Users: 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
Google likes urls that have at least a three digit number. it's a good practice to add the date to the news url, it also adds SEO value as well. Like this http://www.example.com/posts/2012/06/06/my-unique-title
Upvotes: -1
Reputation: 33626
It's all depends on what's the most important subject of your app. Supposing that the main subject of the app is posts, then the URLs for posts would have to be "closer" to the root url.
So they would look like this:
# 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
This involves 2 changes in your routes:
1) Getting rid of "/posts/" in your URLs. To do this you can declare your resource like this:
resources :posts, :path => "/"
2) Getting rid of the id in all the URLs except of post#show (posts from different users may have the same titles sometimes, if not, you could omit the ID in those cases too).
To do this should override the to_param
method in your models like this:
class Post < ActiveRecord::Base
def to_param
"{id}-#{title.parameterize}"
end
end
or use the friendly_id gem if you're finding overriding to_param
difficult.
Upvotes: 5
Reputation: 203
I will admit that my knowledge on SEO is not as far reaching as some of the more experianced people on StackOverFlow. However i do know that when it comes down to URLs generally the 'the shorter and readable the better' rule applies. So using id's in a URL is a big setback and can have a negative impact on your SEO score by google or other search engines.
You can read quite abit about it in the free SEO Starter Guide from google wich you can find on PDF here : http://static.googleusercontent.com/external_content/untrusted_dlcp/www.google.com/nl//webmasters/docs/search-engine-optimization-starter-guide.pdf
The section about URL's is on page 8 of this PDF.
As for your application a way to avoid using ID's would be to use nicknames for your users. You will find this commonly used on forums all over the web. These nicknames always have a unique restriction making sure that there is always only one user with that very nickname. It also makes it possible for you to create restricions for these nicknames, for example prohibbiting the use of numbers in the nickname so people can't go about creating nicknames like John123
.
In the end you want to end up with a url like this :
http://www.example.com/users/uniquenickname
The same idea goes for using categories and tags.
When it comes down to posts you have 2 options really depending on what you exactly mean by a post. If by post you simply mean a blog entry then you can simply use a combination of the category, user and title of the entry to create a unique url.
For example : http://www.example.com/category/uniquenickname/entrytitle
If you ment posts as in comment made on a blog entry then using the URL you provided above will be fine but you might want to add in your robots.txt that the crawler is not allowed to index those urls. The reasoning behind this is that you tend to have spam bots going around blogs posting addvertisements and links to webpages you absolutely do not want to be associated with and you want to prevent the crawler to index these links wich can have a rather negative impact on your SEO score.
I hope this helps :)
Upvotes: 0
Reputation: 4187
Since (I assume) users have unique nicknames, url can be more simply:
http://www.example.com/users/peter
The same can apply to tags and categories. You just do not forget to check the uniqueness of name based on parameterize.
It will also help avoid duplication of objects with similar names:
"peter the great".parameterize => "peter-the-great"
"Peter-THE-Great".parameterize => "peter-the-great"
And this is just my opinion, in most cases used the logic with a unique id-name
or id/name
(look at url of this question :) ).
Upvotes: 0
Reputation: 1380
I've faced the same problem, and I've come across a great gem that makes your urls SEO and human friendly: friendly_id.
Here's a great screencast to get started with it: Pretty URLs with FriendlyId.
I'm not going to go into details here, because i'm sure you'll find everything that you need in the docs or screencast. Happy SEO!
Upvotes: 1