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?

  • Is there no discernable "pattern" that links the old URL to the new URL? But otherwise... "have a 404 set up that checks the JPG requested against a database of old URLs with their corresponding new URL" - yes.
    – MrWhite
    Jan 16 '20 at 10:08
  • Sadly not, gone from original photo filenames to md5-of-photo-content filenames, and also changed the directory structure. I'm a bit confused about how to correctly set the redirects up. At the moment I have a 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"...?
    – Codemonkey
    Jan 16 '20 at 11:00
  • To confirm... is there no SEO motive behind this (is Google image search relevant here)? Or is it just 3rd party backlinks ie. historical emails - places that cannot be updated?
    – MrWhite
    Jan 17 '20 at 1:19
  • Mainly the latter, but obviously I'd like google to update their links over time as well.
    – Codemonkey
    Jan 17 '20 at 8:59
  • I don't really know enough about Nginx to answer, but... there should be no more than one 301 redirect. The fact that your PHP script is on a different subdomain maybe why you are seeing the first redirect. There should either be a single 301 to the new image or a 404. Furthermore, the script should only be processed when there would otherwise be a 404 and for URLs that look like the old URL. Depending on your web application and how URLs are routed through your site then you may not need to change your Nginx config at all?
    – MrWhite
    Jan 20 '20 at 0:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.