Debarshi DasGupta
Debarshi DasGupta

Reputation: 351

nginx proxy pass rewrite rule when the first path parameter is not fixed

Need help with below nginx proxy/rewrite rule -

Request: https://domain1.com/{cc}-{lc}/news/article
--needs to proxy forwarded like below --
Target: https://domain2.com/{cc}-{lc}/info/article

Examples-

Request: https://domain1.com/us-en/news/welcome_2020
--needs to proxy forwarded like below --
Target: https://domain2.com/us-en/info/welcome_2020

Request: https://domain1.com/fr-fr/news/welcome_2020
--needs to proxy forwarded like below --
Target: https://domain2.com/fr-fr/info/welcome_2020

Upvotes: 0

Views: 175

Answers (1)

Ivan Shatsky
Ivan Shatsky

Reputation: 15687

Use

location ... { # your location
    rewrite ^(/[^/]+)/news(/.*) $1/info$2 break;
    ... # all the other proxy setup
    proxy_pass ...
}

Upvotes: 1

Related Questions