On Thu, Apr 21, 2016 at 02:05:24AM -0400, rahulgupta20nov wrote:
try_files $uri $uri/ /hello/some_path/www/$1.$2;
So when I request a json file eg:-
it should be redirect to
But it not redirect to mentioned path.
Your understanding of how regular expressions work is incorrect.
The “/hello/language/locale-en-us.json” URI, when matched by the
regular expression specified, will match at:
Matching full string is not required unless anchors are
Between alternative branches first one is preffered in NFA
algorithm as used by PCRE (an hence nginx), and “js” in your
regex will match.
In this case, correct fix would be to use explicit anchors, “^” at
the start and “$” at the end:
Only “$” is required to fix the problem with “js” vs. “json”,
but “^” is also needed to prevent the regex from matching
“…/hello…” in the middle of other unrelated URIs, and unlikely
it’s something you want to happen.
If you want to understand regular expressions better, consider
Jeffrey Friedl’s excellent book “Mastering Regular Expressions”,