Some details about my product list first:
- Static, contains about 400 items.
- It will not grow any further. Trust me on this one.
- No duplicate item names.
- Properties of products will not change.
Basically think of my product list as the periodic table. I do not see any point of adding the id to the URL with the "slug name" (or whatever it's called). I'd rather have a clean SEO friendly URL. Is there something I'm overlooking here?
Here's the thing about IDs and slug names:
Using "product-id":
Usually, URLs are designed using the ID:
But they are too little descriptive about what's exactly in that URL (I mean, different URLs will have different IDs, but this alone - just by looking at it - will not give you any information about that specific URL.)
Botoom line: ID-only is bad because it is little descriptive.
Using "product-name":
Using:
Is actually pretty good, the caveats are:
[product-name]
into a[product-id]
?[product-name]
) change a lot, what if someone bookmarks an old title?Using "[product-id]/[product-name]":
Using:
In this approach, you get the product by the
id
part of the URL.Gives you the best of both worlds: descriptive urls AND easy to map urls AND titles (names) can change without making old URLs useless.
Your scenario:
So, if you are 100% certain you'll never change your products' name, you can go on and use "product-name". Just find a way to map that "product-name" into a "product-id" in an efficient way.
Bonus: Make sure you check out this nice article about the importance of using slug names and search engines.
The only reason i can think of is that to use /products/[id]-[name], you need to know both the id and the [name], to use the second option you only need to know the name.
A more common choice here would be to use : /products/[id]
I would only consider /products/[name] if you are confident if name is: short, unique, does not contain any special characters (&, ? #, / , ...)
Since whatever is at the end of the url is what your app will use to look up the product in the database, this turns into a database question. Keeping the id in the url lets your app look things up by id.
If your product names will never ever change, and you can actually use the product name as a primary key (or at least have a unique index on the colum) in your database, then you might get away with using just the product name in your URL as well.
Usually, it's better practice to have a unique, meaningless field as your primary key, because things like product names tend to change in most cases, even if only to fix typos.