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:

http://domain.com/subdomain/page.html          <-- Original URL
http://domain.com/W7zjcTP5/subdomain/page.html <-- Changed URL
http://domain.com/jfP7x9sZ/subdomain/page.html <-- 1 day later
http://domain.com/eh7PjCzG/subdomain/page.html <-- 2 days later
http://domain.com/JF8scd4d/subdomain/page.html <-- 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!

Hi,

i really wonder how this should be related to ownCloud?