Last and break of nginx rewrite

Source: Internet
Author: User

After the last: rewrite match, a request is initiated again, and only the rules in location are matched again.

After the break: rewrite matches, no request is initiated or the following rules are matched.


Example:

Location /{

Root html;

Index. php index.html index.htm;

}

If ($ request_uri ~ */Cms /){

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

# You can also use last here. if it is processed only once

# "If" and "(" space required

}


Location /{

Root html;

Index. php index.html index.htm;

If ($ request_uri ~ */Cms /){

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

# Here, using last will cause an endless loop, and if in location will process multiple times

}

}


Note that the url has question marks.

Do not add "? "And add "? "Marked URL jump differences

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

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

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


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

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

Http://www.yourdomain.com/home




This article from the "fly World" blog, please be sure to keep this source http://liuping0906.blog.51cto.com/2516248/1301125

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.