Mobile app version of vmapp.org
Login or Join
Goswami781

: How should I properly redirect 1 million+ URLs? 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

@Goswami781

Posted in: #Redirects #Url

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.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Goswami781

1 Comments

Sorted by latest first Latest Oldest Best

 

@Rambettina238

I would advise to keep a MySQL table that saves the mapping of the file id, to the directory it is kept in. You shouldn't be worried about the DB load considering 1.5M rows and millions of queries per day. For such a simple 1:1 link query. Just make sure you add the proper index to the key you search according to, and if you wish to be better prepared for scale, keep the key an number.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme