I have the following configuration in nginx for redirecting in a certain scenario.
location /prefix-someurl {
if (condition) {
return 301 $scheme://$host/xyz.html;
}
proxy_pass someValue;
}
and in another block there are some rewrite rules like this
location /someurl {
if (condition) {
rewrite ^(.*)abc(.*)$ $1test/abc$2 break;
rewrite ^(.*)someurl/$(.*) $1someurl/test/index.html$2;
}
proxy_pass value;
}
The above configuration works as intended. However if for the latter I make this modification;
location /someurl {
if (condition) {
return 301 $scheme://$host/xyz.html;
}
if (condition) {
rewrite ^(.*)abc(.*)$ $1test/abc$2 break;
rewrite ^(.*)someurl/$(.*) $1someurl/test/index.html$2;
}
proxy_pass value;
}
I get too many redirect errors for accessing /prefix-someurl
.If I modify the /someurl
to the following the error goes away;
location /someurl {
if (condition) {
return 301 $scheme://$host/xyz.html;
}
proxy_pass value;
}
I cannot understand why modifying /someurl
has an impact on /prefix-someurl
. Or am I missing something regarding nginx rewrite evaluation. Insight on this would be appreciated.