The difference between the last of Nginx rewrite and the break

Source: Internet
Author: User

Once the last:rewrite is matched, a request will be initiated again, and only the rules in the location will be matched again.

After a match is break:rewrite, the request is not initiated and the subsequent rules are not matched.

Example:

Location/{

root HTML;

Index index.php index.html index.htm;

}

if ($request _uri ~*/cms/) {

Rewrite "^/cms/(. *) \.php"/cms/index.php break;

# The last can be used here, and the single if only once

# "If" and "(" Requires spaces

}

Location/{

root HTML;

Index index.php index.html index.htm;

if ($request _uri ~*/cms/) {

Rewrite "^/cms/(. *) \.php"/cms/index.php break;

# using last here will cause a dead loop, and the IF in the location will handle multiple

}

Need to be aware of URLs with question marks

Compare without "?" and add "?" URL Jump Differences for tags

Rewrite ^/test (. *) $ http://www.yourdomain.com/home permanent;

Access http://www.yourdomain.com/test?id=5 after 301 jumps the URL is

Http://www.yourdomain.com/home?id=5

Rewrite ^/test (. *) $ http://yourdomain.com/home? Permanent

Access http://www.yourdomain.com/test?id=5 after 301 jumps the URL is

Http://www.yourdomain.com/home

Reproduced in: http://liuping0906.blog.51cto.com/2516248/1301125

The difference between the last of Nginx rewrite and the break

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.