Nginx Redirecting from file list

configurationnginxredirect

I would like nginx to perform redirects (302) on certain urls while changing part of the url to another based on a file (lets say a csv). For example:

https://localhost/foo/100/bar.html to redirect to https://localhost/foo/209/bar.html

https://localhost/foo/102/bar.html to redirect to https://localhost/foo/1000/bar.html

https://localhost/foo/99/bar.html doesn't redirect

Because the file(lets say again csv) has the lines:

"old";"new"
100; 209
101; 203
102; 1000
...

Is it possible without an application server (proxy pass)?

Best Answer

Not that I know of, not from CSV. You need to list your redirects manually.

location https://localhost/foo/100/bar.html {
    return 301 https://localhost/foo/209/bar.html;
}
location https://localhost/foo/102/bar.html {
    return 301 https://localhost/foo/1000/bar.html;
}

However you could try the technique suggested in this SF post, using Maps. It's not CSV but it's easier than manual maintenance of redirect rules.