Nginx Match question mark rewrite

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.