Mass 301 redirect URLs with Nginx

I have a list of 600 urls. Due to a change in the system the urls will change to a new format. I will have a list with the old urls and corresponding new ones. But how do i 301 redirect all of them?

example:

/news/post-name -> /news/post-name.html
/wordpress/στα-ελληνικά -> /wordpress/sta-ellinika.html (in greek)
/cms/a-big-long-title-with-a-lot-of-te -> /cms/a-big-long-title-with-a-lot-of-text.html

There is no real pattern that could automate the work.

So what is the correct way to redirect all of them?


Solution 1:

You could use the map module to simplify the nginx configuration somewhat, but you're going to have to write a script to convert your list of URLs into the correct format for nginx. I would suggest generating the map directive into a separate file which is then included by the main configuration.