The rewrite directive in Nginx

Source: Internet
Author: User

Rewite
.
Under the server block, the rewrite section is executed first, and then the location block is matched.
There is no difference between rewrite break and last in server, it will match location, so there is no need to use last to initiate a new request, you can leave blank
.
.
Rewirte in the location:
.
Do not write last and break-then the process is to execute these rewrite in turn
Rewrite Break-url rewrite, directly use the current resource, no longer execute the remaining statements in the location, complete this request, Address bar URL unchanged
Rewrite Last-url rewrite, immediately launch a new request, again into the server block, retry location matching, more than 10 matches are not reported 500 error, address bar URL unchanged
.
Rewrite redirect– returns 302 temporary redirect, the address bar displays the redirected URL, and the crawler does not update the URL (because it is temporary)
Rewrite permanent– returns 301 permanent Redirect, Address bar displays redirected URL, crawler update URL
.
Use last to re-initiate a request to the server label
If the location in the rewrite is a request for a static resource, do not need to make another match, generally use break or do not write, directly using the data source in the current position, complete the request
If the location is rewrite, additional processing is required, such as a dynamic fastcgi request (. php,.jsp), to continue with the last new request
(The root location uses last better, because if there is. PHP and other fastcgi requests to continue processing)
.
Use alias to specify source: must use Last
.
The IF statement is primarily used to determine conditions that cannot be directly matched in rewrite statements, such as detecting file presence or not, HTTP Header,cookie, etc.

.
Location-matching rules and priorities
1. = Match this query strictly. If found, stop the search.
2. ^~ matches the path prefix and, if found, stops the search.
3. ~ For case-sensitive regular matching
4. ~* for case-insensitive matching
Priority: =, ^~, ~/~*, none

.
Break statement
Put in front of the server block rewrite statement
If you are requesting a real file directly, stop the rewrite check with the break statement
if (-f $request _filename) {
Break
}

The rewrite directive in Nginx

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.