Some problems of Nginx rewrite rules, about the difference between last and break

Source: Internet
Author: User
So, I want to implement a url:example.com/test.php/a/b/c, the Web directory has a test.php file, want to receive/a/b/c as routing parameters to implement the routing function.
If you do not set the Rewite rule, it is possible to open example.com/test.php, but open example.com/test.php/a/b/c will report 404. And then I just want to rewrite the rules myself.
After trying a lot of times, I found

location /test.php {    rewrite . /test.php last;                                                                                                                                                                                 }

This will make the page normal access, and PHP $_server[' Request_uri '] is test.php/a/b/c, to meet my needs. But it's not right to change last to break.

I would like to know why the last can be successful rewrite, has the URL rewrite to/test.php, why the/a/b/c/can still be retained? And why not use a break.
And last this flag, will not stop the location of the match Ah, test.php was rewrite to test.php should still enter this location and infinite loop return 500 is. Why does this work?
Although I have achieved the function I want, but I really do not know what the reason for this.

Reply content:

So, I want to implement a url:example.com/test.php/a/b/c, the Web directory has a test.php file, want to receive/a/b/c as routing parameters to implement the routing function.
If you do not set the Rewite rule, it is possible to open example.com/test.php, but open example.com/test.php/a/b/c will report 404. And then I just want to rewrite the rules myself.
After trying a lot of times, I found

location /test.php {    rewrite . /test.php last;                                                                                                                                                                                 }

This will make the page normal access, and PHP $_server[' Request_uri '] is test.php/a/b/c, to meet my needs. But it's not right to change last to break.

I would like to know why the last can be successful rewrite, has the URL rewrite to/test.php, why the/a/b/c/can still be retained? And why not use a break.
And last this flag, will not stop the location of the match Ah, test.php was rewrite to test.php should still enter this location and infinite loop return 500 is. Why does this work?
Although I have achieved the function I want, but I really do not know what the reason for this.

Last after the rule is matched, it jumps to the rule and goes inside.
Break does not match to the rule.
That's the difference between the two.

  • Related Article

    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.