Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL without ID

I see often (rewritten) URLs without ID in it, like on some wordpress installations. What is the best way of achieve this?

Example: site.com/product/some-product-name/

Maybe to keep an array of page names and IDs in cache, to avoid DB query on every page request? How to avoid conflicts, and what are other issues on using urls without IDs?

like image 489
Hrvoje Hudo Avatar asked Aug 16 '08 16:08

Hrvoje Hudo


1 Answers

Using an ID presents the same conundrum, really--you're just checking for a different value in your database. The "some-product-name" part of your URL above is also something unique. Some people call them slugs (Wordpress, also permalinks). So instead of querying the database for a row that has the particular ID, you're querying the database for a row that has a particular slug. You don't need to know the ID to retrieve the record.

like image 147
Brian Warshaw Avatar answered Oct 18 '22 17:10

Brian Warshaw