Rewrite command break, last, redirect, permanent in Nginx

Source: Internet
Author: User
: This article mainly introduces the rewrite commands break, last, redirect, and permanent in Nginx. if you are interested in PHP tutorials, refer to them. Reprinted from: rewrite command (break, last, redirect, permanent) in Nginx)

Rewite

In the server block, the rewrite part is executed first, and then the location block is matched.
There is no difference between the rewrite break and last in the server, and the location will be matched, so there is no need to use last to send a new request, you can leave it blank

Rewirte in location:

Do not write the last and break-then the process is to execute these rewrites in sequence
1. after rewrite break-url is rewritten, the current resource is used directly, and the remaining statements in location are not executed to complete the request. the url in the address bar remains unchanged.
2. after rewrite last-url is rewritten, a new request is initiated immediately to enter the server block again, and location matching is retried. if there are more than 10 matches, a 500 error is returned, and the url in the address bar remains unchanged.
3. rewrite redirect-302 temporary redirection is returned. the address bar displays the redirected url. crawlers will not update the url (because it is temporary)
4. rewrite permanent-returns the 301 permanent redirect. the address bar displays the redirected url. the crawler updates the url.

Using last will re-initiate a request to the server tag

If the rewrite request in location is a static resource request, no other matching is required. Generally, you must use break or do not write the request. you can directly use the data source in the current location to complete the request.
If other processing is required after rewrite in location, such as dynamic fastcgi requests (. php,. jsp), use last to initiate new requests.
(It is better to use last for the root location, because if a fastcgi request such as. php still needs to be processed)

Use alias to specify the source: you must use last

The if statement is mainly used to determine conditions that cannot be directly matched in the rewrite statement, such as checking whether a file exists, http header, cookie, etc.

Location matching rules and priority

  1. = Strictly match this query. If yes, stop searching.
  2. ^ ~ Match the path prefix. if it is found, stop searching.
  3. ~ For case-sensitive regular matching
  4. ~ * Case-insensitive match
    Priority: =, ^ ~, ~ /~ *, None

Break statement

Before the server block rewrite statement
If you directly request a real file, use the break statement to stop the rewrite check.
If (-f $ request_filename ){
Break;
}

'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
  • '). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script

    The above describes the rewrite commands break, last, redirect, and permanent in Nginx, including the following content. I hope to help some friends who are interested in PHP tutorials.

    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.