Home > Backend Development > PHP Tutorial > rewrite instructions break, last, redirect, permanent in Nginx

rewrite instructions break, last, redirect, permanent in Nginx

WBOY
Release: 2016-07-29 09:12:16
Original
1047 people have browsed it

Reprinted from: rewrite command (break, last, redirect, permanent) in Nginx

rewite

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

rewirte in location:

Do not write last and break - then the process is to execute these in sequence rewrite
1. rewrite break - After the url is rewritten, the current resource is used directly, and the remaining statements in the location are no longer executed. This request is completed, and the address bar url remains unchanged
2. rewrite last - After the url is rewritten, immediately initiate a new request, enter the server block again, and retry the location matching. If the match fails for more than 10 times, a 500 error will be reported, and the address bar url remains unchanged
3. rewrite redirect – returns 302 temporary redirect, the address bar displays the redirected url, and the crawler will not update the url (because it is temporary)
4. rewrite permanent - returns 301 permanent redirect, the address bar displays the redirected url, and the crawler updates the url

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

If the rewrite in the location is a request for static resources, no need For other matching, generally use break or do not write, directly use the data source in the current location to complete this request
If after rewriting in the location, other processing needs to be performed, such as dynamic fastcgi requests (.php, .jsp), etc., you need to use last to continue to initiate new requests
(It is better to use last for the root location, because if there are fastcgi requests such as .php, it will continue to be processed)

Use alias to specify the source: you must use last

if statement is mainly used to determine some conditions that cannot be directly matched in the rewrite statement , such as detecting the existence of files, http headers, cookies, etc.

location matching rules and priorities

  1. = strictly match this query. If found, stop searching.
  2. ^~ Match the prefix of the path, if found, stop searching.
  3. ~ is a case-sensitive regular match
  4. ~* is a case-insensitive match
    Priority: =, ^~, ~/~*, no

break statement

is placed in front of the server block rewrite statement
If you are directly requesting 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 ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the rewrite instructions break, last, redirect, and permanent in Nginx, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template