Vote Charlie!

Generate nested redirects from CSV file

Posted at age 27.
Edited .

One of my work clients is undergoing a migration from Movable Type to WordPress, and the decision was made to change the URL structure of basically every piece of content. While not ideal, this move can make sense, especially if the old structure wasn’t very future proof and started causing duplicate URL conflicts.

Faced with the prospect of installing around 40,000 redirects, I decided to write a script to automate this. Specifically, I am automating the generation of the redirects from a CSV file that Julia created from the WordPress database, which includes a custom field containing the original URLs from Movable Type, which we built into the migration process.

Since there are so many redirects, and the most I could find online was suspicions Apache or Nginx can handle “thousands” of redirects without slowing down too much, I came up with a theory I might be able to mitigate any performance decrease by breaking the redirects into nested location blocks. I have yet to test this, but I published the work at github.com/CNG/redirects-generator so hopefully anyone else Googling “redirects from CSV file” might stumble here and save some time.