This question is actually quite close to my requirement where, the Nginx configuration rewrites the URL for $1
.
Reproduced here:
location /foo {
rewrite /foo/(.*) /$1 break;
proxy_pass http://localhost:3200;
proxy_redirect off;
proxy_set_header Host $host;
}
Whereas, in my case the original URL may have any number of levels of nesting and query parameters My requirement is to maintain those levels and prepend a level.
Examples:
Original URL: https://apis.demo.com/books/12414
Desired URL: http://localhost:3000/prepend/books/12414
Original URL: https://apis.demo.com/books/12414?find=meta
Desired URL: http://localhost:3000/prepend/books/12414?find=meta
Original URL: https://apis.demo.com/library/LIB001/books/12414
Desired URL: http://localhost:3000/prepend/library/LIB001/books/12414
Original URL: https://apis.demo.com/library/LIB001/books/12414/history
Desired URL: http://localhost:3000/prepend/library/LIB001/books/12414/history
How do we achieve this?