Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AR's avatar
Level 7

what is the best way to achieve unique urls for each item

I have a shopping website where each product within a shop has its own page. I don't want to have the url for each product as slug like "/p/the-best-laptop". I want to generate random value like the way Instagram or other sites are doing for example "/p/BT3VQ5yA0mx/". What is the right way to do it and be sure that each url will be unique.

Please advice

0 likes
3 replies
AR's avatar
Level 7

I think the one fits my case is hashids which @ohffs suggested because I will not need to store anything? I mean can I just generate the links on the fly?

For example the id of 1 will be encoded to "ATX15" and then when I go to my route which will be "example.com/p/ATX15" I will decode that value in the controller to convert it to the right id. So no need to store the values? Is that correct?

Please or to participate in this conversation.