look up the new URL in an array or in a database
Yeah, that's essentially what I'm talking about. Let me elaborate a bit on what I'm thinking of doing, because I'd love to hear feedback on it.
The pages I'm thinking of removing are image detail pages. They basically have a high-res version of an image (the thumbnail of which appears on a subcategory page) and a caption and nav to the next and previous images. Formerly, it made sense to have each of these on its own URL, now not so much. So what I'm thinking of doing is:
-Put the full caption text on the subcategory page where the thumbnail of the image appears. Set these pages up to display the full images in a lightbox using JS as this will not create a separate URL for each image (with JS off, just link straight to the image file).
-Replace each image page with (essentially) a script that determines the appropriate page to redirect to and returns the redirect. This redirect will point to the subcategory page with a query string parameter that causes the image in question to open in the lightbox display, so that a visitor to the old URL will see the same image at the same resolution as it was previously on the image page.
-Use a canonical element to suggest that Google consider the subcategory page as a single page rather than separate pages for each query string, since it will contain nearly identical HTML content regardless of the query string.
Thus there will be several (maybe a dozen or so) old URLs redirecting to the same base URL, which I don't think is excessive especially because the exact same content will be there. A visitor to the old page will see content nearly identical to what they would have seen before, just in a lightbox rather than on a separate page. Link juice is preserved and hopefully consolidated into the single subcategory URL, which now has lots of unique content and causes visitors to spend much more time on the same "page" while they scroll through the images.
With smart preloading it should perform better and feel smoother to the visitor, preserve site functionality, and consolidate superfluous URLs without sacrificing juice or clicks in a way that should appear pretty much seamless to the average visitor. Any downside you guys can think of?