tags:

views:

84

answers:

2

I was thinking about how i should write my URLs. I want them to A) Be user friendly B) SEO C) allow fast DB queries. The information i have are username, category, mediaId, title and other data i dont feel is necessary (date, hash, etc).

Should i have the username before or after the domain name? (username.mysite.com/ vs mysite.com/username/).

Then i need to decide if i should use /media/The-Title-Of-Media or /media/mediaId/The-Title-Of-Media (media being 8 or 16 digit number) or any variants (such as media/The-Title-Of-Media-MediaId).

Do i want a mediaId in there? i was thinking it could speed up the db query but if i am validating it against the username (so mysite.com/deceptiveUserName/media/mediaId/title is not allowed) just using WHERE userid=expectedUserId may be a hairline less efficient then a query using a primary key? Also using a mediaId allows the title to not be unique but would it be a bad idea to allow users to lazily not give everything a unique title? if i allow lazyness users may look at a url before and after and think they are the name due to title. Or it become hard to find a link in a list of links?

-edit-

Hows this. mysite.com/username/media/mediaId/title. If the title happens to change i can update the URL and not break links bc the mediaId is still the same.

+5  A: 

Having subdomains can complicate things like SSL and cookies. Avoid them if possible.

Always supply the primary key if you can.

Don't over-engineer this. SEO comes from having well-structured and relevant content, not shenanigans with URL manipulation.

SpliFF
+1: Also, users rarely enter URL's -- they click links. They do, however, bookmark URL's. Good URL's never change -- so they have to include the actual PK in addition to any name slugs.
S.Lott
+1  A: 

StackOverflow includes the question Id in the Url, so it must be a good practice. :)

I agree with your final thought: mysite.com/username/media/mediaId/title

James Lawruk