Today, my colleague asked me Nignx jump question match question mark need
Demand is http://aaa.bbb.com/forum.php?id=123 jump to http://aaa.bbb.com/forum.php
It is important to note that there is a question mark before the jump and no question mark after jumping.
I solved this situation with the IF.
Nginx has a variable that is $query_string its purpose is to define the variable after the question mark
In this case, it's actually just a few characters of id=123.
The time to start configuring is
if ($query _string ~* "id=123$") {rewrite ^ (. *) http://aaa.bbb.com/forum.php last;}
But the test results are 302 dead loops.
Later, the Nginx rewrite directly matches the contents of the question mark before it, and the contents after the question mark are added directly rewrite
This will cause, each rewrite after the URL will be added id=123 so, jump before and jump after there is no difference.
Effect is
http://aaa.bbb.com/forum.php?id=123 rewrite http://aaa.bbb.com/forum.php?id=123
This can be seen from the location in the Http_header. Such jumps every time the location is
Http://aaa.bbb.com/forum.php?id=123. This will cause a cycle of death.
Later view wiki nginx jump Remove question mark content is this operation
Rewrite ^ (. *) http://aaa.bbb.com/forum.php? Last
is to add a question mark after the rewrite URL, so that the question mark before the jump is no longer appended to the post-challenge link.
The correct configuration is:
if ($query _string ~* "id=123$") {rewrite ^ (. *) http://aaa.bbb.com/forum.php? last;}
This article is from the "Floating Guest" blog, please be sure to keep this source http://zhqaihnn.blog.51cto.com/5257485/1738144
Nginx Match question mark rewrite