I have a server that allows file uploads. Foolishly I let everything get stored in one directory
/uploads. Now that I am approaching 1.5M files in this directory, I want to go back and correct my mistake. I am going to move all files into date based directories like so
/uploads/2/14/file.ext. How can I do this without ruining all links that currently exist to the files? If someone tries to access
site.com/uploads/file.ext it needs to show them the content from
site.com/uploads/2/14/file.ext. How do sites like Imgur make it seem as if all their files are stored in one directory?
Things I have thought of:
- .htaccess redirect (I think this would be way too many URLs to store in this type of file).
- MySQL based redirect (I think this would cause way too much load on the DB as there are millions of files viewed each day.