I certainly don't want to list 4 million redirects in my nginx config files... what's the best practice with a large number of redirects like this? They'd be permanent as well as the old links live in a lot of customers' historical emails, so I can't count on Google et al updating their indexes over time.
I suppose I need to have a 404 set up that checks the JPG requested against a database of old URLs with their corresponding new URL?
try_files $uri @missing;
where @missing then 301 redirects to a PHP page on a different subdomain. That page does the DB lookup, and if it finds something does a 301 redirect to the correct image. It works, but two redirects feels "messy"...?