简体   繁体   中英

Using SEO-friendly links

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?

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.

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.

SO 'cheats' :-).

The link for your question is " Using SEO-friendly links " but " Using SEO-friendly links " 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

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.

To avoid dealing with the links contain special characters, you can use this plugin for Zend Framework.

https://github.com/btlagutoli/CharConvert

$filter2 = new Zag_Filter_CharConvert(array(
               'onlyAlnum' => true,
               'replaceWhiteSpace' => '-'
           ));
echo $filter2->filter('éééé ááááá ? 90 :');//eeee-aaaaa-90

this can help you deal with strings in other languages

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM