Create unique IDs between URL with nginx

I searched and tried nearly two weeks but don't get any useful result, so I'm trying my luck here before I get crazy:

Every existing domain should get an unique ID right after the domain. The ID should be 8 digits and contains a random value a-z,A-Z,0-9 which changes automatically every 24 hours.

For example:          <-- Original URL <-- Changed URL <-- 1 day later <-- 2 days later <-- 3 days later

But when someone saved the link 5 days ago, this link should still be usable and accessable, so thereforce there must be saved the actual active ID and all used IDs for each URL somewhere, to redirecting to original URL.
Also when one ID was used before, it must not used never again. When using a generated ID there also have to be a check if this ID was created before.

I really get stuck and don't know how to solve this problem, thank you for your help!


i really wonder how this should be related to ownCloud?