tags:

views:

280

answers:

5

Hi

I'm developing a PHP website, and currently my links are in a facebook-ish style, like so

me.com/profile.php?id=123

I'm thinking of moving to something more friendly to crawling search engines (like here at stackoverflow), something like:

me.com/john-adams

But how can I differentiate from two users with the same name - or more correctly, how does stackoverflow tell the difference from two questions with the same title? I was thinking of doing something like

me.com/john-adams-123

and parsing the url.

Any other recommendations?

+5  A: 

In stack overflow's case, it's

http://stackoverflow.com/questions/975240/using-seo-friendly-links

http://stackoverflow.com/questions <- Constant prefix
/975240                            <- Unique question id
using-seo-friendly-links           <- Any text at all, defaults to title of question.


Facebook, on the other hand, has decided to just make everyone pick a unique ID. Then they are going to use that as a profile page. Something like http://facebook.com/p/username/. They are solving the problem of uniqueness between users, by just requiring it to be some string that the user picks that is unique among all existing users.

sharth
+6  A: 

Stackoverflow does something similar to your me.com/john-adams-123 option, except more like me.com/123/john-adams where the john-adams part actually has no programmatic meaning. The way you're proposing is slightly better because the semantic-content-free numeric ID is farther to the right in the URL.

What I would do is store a unique slug (these SEO-friendly URL components are generally called slugs) in the user table and do the number append thing when necessary to get a unique one.

chaos
actually, it's better to use numeric IDs because of better database performance when using indexed columns of rather short integer values compared to rather long string (varchar) values.
zappan
+3  A: 

SO 'cheats' :-).

The link for your question is "http://stackoverflow.com/questions/975240/using-seo-friendly-links" but "http://stackoverflow.com/questions/975240/" also works.

The part after the number is the SEO friendly bit, but SO doesn't really care what's there. I think it defaults to the question title.

So in your case you could construct a link like:

me.com/123/john-adams

a second john adams would have a different Id and a unique URL like :

me.com/111/john-adams
Glen
A: 

I'd go with your style of me.com/john-adams-123, because I think the leftmost part of the URI has more importance in SEO ranking.

Actually, if you are willing to use this on several controllers (not just user profile), you may want to do it more like me.com/john-adams-profile-123 with a rewriting rule redirecting /.+-profile-(\d+) to profile.php?uid=$1 and still be able to use, say, me.com/john-adams-articles-123 for this user's articles...

streetpc
+1  A: 

I would say that your proposed solution is a better solution to that of stackoverflows as it preserves content hierarchy:

me.com/john-adams-123

Usage of the unique ID before the username is simply nonsensical.

I would, however, recommend enforcement of content type:

me.com/john-adams-123.html

This will allow for consistent urls while serving a variety of content types.

Additionally, you could make use of sexatrigesimal for the unique id, to further reduce the amount of unnecessary cruft in your URL, especially for high end numbers, but this is often overkill :D

me.com/john-adams-123.html -> me.com/john-adams-3F.html
me.com/john-adams-1234567890.html -> me.com/john-adams-KF12OI.html

Finally, be sure to utilize 301 redirects on non-conforming accessible URIs to redirect to the "correct" seo-friendly schema to prevent duplicate content penalties.

Matt
I learned something today - sexatrigesimal. Thanks :)
Anthony Lewis