0

I have seen websites generate short urls, where they convert IDs for items into a 4 letter string. Here's an example: https://boxd.it/nrI0

This is for a website called Letterboxd, and the link takes you to a movie page. I'm guessing behind the scenes the movie has an integer ID that is then converted into this 4 letter string (or maybe its stored as that 4 letter value to begin with?)

How is this accomplished?

Human Cyborg Relations
  • 1,202
  • 5
  • 27
  • 52

1 Answers1

1

In general, there are many options to do this. But in most cases there is no direct relation between integer ID and generated slug for short URL. I am pretty sure this case is not exception. I suppose they just generate random 4 letter string that never used before and maintain relation between film and short URL at the database level.

Oleksii Tambovtsev
  • 2,666
  • 1
  • 3
  • 21
  • Could you backup your sentence 'in most cases'? I think the opposite and have an idea how to check it in this case. – kosciej16 Dec 21 '21 at 11:58
  • @kosciej16 You can think of many options to get 4 letter string from integer. @Arne already gave an example. It can also be any hash-solution (for instance, `md5`), but using only 4 letters of hash (need some more specific logic to avoid collisions in specific case). But if you don't have any insider information, it will be very hard too guess :) – Oleksii Tambovtsev Dec 21 '21 at 17:08