views:

441

answers:

10

Alright, so let's say I'm writing a forum application, and I want pretty URLs. However, all my tables use numeric IDs, so I'm not sure the best way to format the URLs for those resources. Let's pretend I'm trying to get a topic with ID 123456 and title This is a forum post. I've seen it done a couple ways:

  1. www.example.com/topic/123456
  2. www.example.com/topic/this-is-a-forum-post
  3. www.example.com/topic/123456/this-is-a-forum-post

Which one would you say is, taking all things into consideration (including SEO), the optimal URL?

Sorry if this question is too vague, but it seems programming-related and it's not incredibly open-ended, as I just want to hear the pros and cons of each method.

+2  A: 

I would think that the 2nd URL would be the best for SEO since it is meaningful and has less depth. It's nicer for people as well since you can look at the URL and know what the content is about.

Gromer
+10  A: 

I would go with option 3, and make the slug (the last bit) optional

Because?

  • The ID will always be unique... 2 people may make a thread with the name 'good news' for example
  • The search bots can access the slug for some SEO goodness
  • The slug should be optional ... Using just the ID should still give you access to the site. Perhaps if the slug isn't there you could forward to the slug'd version, if you're concerned about duplicate content. You could always use the canonical meta tag to tell Google to index the slugged version.
  • Another benefit of the optional slug is if someone copies and pastes the URL into a document, there is a chance it could have characters at the end chopped off (because URLs generally don't have spaces, so they don't break to new lines). Having the slug optional means there is more of a chance people will find your page.

I believe this is what Stack Overflow does.. and also notice they are doing rather well in the Search Engines.

alex
Hmm, I was going to ask you whether I should make the 'slug' optional but looks like you read my mind. Thanks! :)
musicfreak
Haha, I can do that sometimes!
alex
Make sure to define your canonical URL within the page.
Joe Philllips
if you make the slug optional, be sure to redirect incorrect or missing slugs to the correct, canonical version. This ensures that search engines will only see a single page. (stackoverflow.com does it wrong)
levinalex
@levinalex, good idea, I would do this also.
alex
+3  A: 

URL 1 is definitely suboptimal. URL 2 is attractive but you run the risk of confusion if tags collide, especially if they differ only in punctuation. So I'd say URL 3 is the clear winner.

Also note that just because you display URL 3 is no reason not to accept all 3, with the other two redirecting. If URL 2 is ambiguous, it should redirect to a disambiguation page.

Norman Ramsey
Last sentence is a great idea.. sort of like Wikipedia!
alex
Hmm, definitely a good idea (supporting all three). I'll look into that. Thanks.
musicfreak
A: 

Stackoverflow seems to using pattern 3, with the title being ignored completely (just the id is used).

That makes for nice semantic URL, and is also easy to implement, and still works if the title changes later.

Of course, the title could be completely fake:

http://stackoverflow.com/questions/851140/who-is-the-best-captain-the-uss-enterprise-has-ever-had

Thilo
Good point, but that doesn't actually matter, does it? I can't think of a situation where that would be a threat to either SEO or security.
musicfreak
No, I don't think it is a problem. It works just like putting names in email headers. Ignored by the system, but a good way to store/transmit annotations for humans.
Thilo
+2  A: 
  1. Doesn't include the title, so you'll lose the additional SEO value of having those keywords in the URL.

  2. Won't work well, because it doesn't have a unique numerical ID, so what are you going to do if someone else tries to post a topic titled "This is a forum post"? Then you start getting into the weird thing digg does, where it has to give the second one the url "http://www.example.com/topic/this-is-a-forum-post_2", and so on. It makes it harder to take the URL they tried to load, and figure out exactly which topic they were trying to get to.

  3. Has the best of both worlds, this would be my style of choice.

Chad Birch
You're right, method #2 doesn't look good at all when there are duplicates. Didn't think about that.
musicfreak
A: 

i would suggest the first one, since the topic title can be changed for clarity, by the admins and then the url will be inconsistent.

www.example.com/topic/123456

also allows one to just edit the last bit of the url (the numbers and jump to another topic), not likely to happen but still a usable feature.

Sujoy
+1  A: 

I'll go for the first one. You know it really doesn't matter now. Since there are Long URLs converter and it will just proliferate and will become the norm in the future. Remember the longer your URL the less SEO points you'll get.

And you can't control the way people name their forum topics. So really, I'll just choose the first one for simplicity and the norm.

rymn
+1  A: 

For SEO/traffic, definitely no.2 without a doubt. Get those meaningless numbers out of the URL every single time.

www.example.com/topic/this-is-a-forum-post

pickup the "this-is-a-forum-post" from your database and map it back to the ID number within your database via a query. Then do an internal URL re-write to the real page, something like /topic.php?ID=324342

Aaron
+1  A: 

I would go with option 2, as SEO can better understand.

Stack Overflow uses the third way, probably, that is the reason, Stack Overflow urls were not optimized for SEO. I am not sure in the above answer.

But In my experience with Google, Quite Often, I could see a solution from other forums, whereas stackoverflow solutions were almost invisible.

http://stackoverflow.com/questions/851140/best-way-to-format-pretty-urls-for-numeric-ids http://stackoverflow.com/questions/851140

if the both urls were one and the same, the SEO simply goes with option 2, which is less optimized.

Smart Pandian
+1  A: 

I'm not convinced longer URL's are SEO trouble. The depth seems to be a bigger issue, and not by counting slashes, but by steps it takes to get from an indexed page with rank to the content page. I recently created a dummy test page titled /content/roofing/how-much-does-a-shingle-roof-cost.html and threw it on the server just to test pathways and make sure my directories were working correctly. I'm not even sure how google discovered the page but it did and it started getting traffic, so I had to give it content and make it part of the family. The dummy content was a copy of our about page so it wasn't empty, but I was surprised an unpromoted page would get traction, and think the URL had something to do with that.

Which brings up a slight alternative to the above 3 choices for a URL. What if you went with number 3 but added .html to the end? I generally do this with dynamic URL's but I have no concrete evidence that it's helpful. According to Google they brag that they can index dynamic URL's just fine and so there's no need to do URL rewrites at all. Google doesn't mind a bit if the other engines aren't as good at that. Several sites I trust add the html at the end (blogger for example) and it can't hurt, so I still do it.

Qualsmith
Good find. But how would the .html help?
musicfreak
the .html just tells the engine that it's more likely to be a static document, or at least that you intend it to be treated that way - and does that help? I'm not sure.
Qualsmith