search
HomeBackend DevelopmentPHP Tutorialrewrite instructions break, last, redirect, permanent in Nginx

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.

Statement
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
Explain how load balancing affects session management and how to address it.Explain how load balancing affects session management and how to address it.Apr 29, 2025 am 12:42 AM

Load balancing affects session management, but can be resolved with session replication, session stickiness, and centralized session storage. 1. Session Replication Copy session data between servers. 2. Session stickiness directs user requests to the same server. 3. Centralized session storage uses independent servers such as Redis to store session data to ensure data sharing.

Explain the concept of session locking.Explain the concept of session locking.Apr 29, 2025 am 12:39 AM

Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

Are there any alternatives to PHP sessions?Are there any alternatives to PHP sessions?Apr 29, 2025 am 12:36 AM

Alternatives to PHP sessions include Cookies, Token-based Authentication, Database-based Sessions, and Redis/Memcached. 1.Cookies manage sessions by storing data on the client, which is simple but low in security. 2.Token-based Authentication uses tokens to verify users, which is highly secure but requires additional logic. 3.Database-basedSessions stores data in the database, which has good scalability but may affect performance. 4. Redis/Memcached uses distributed cache to improve performance and scalability, but requires additional matching

Define the term 'session hijacking' in the context of PHP.Define the term 'session hijacking' in the context of PHP.Apr 29, 2025 am 12:33 AM

Sessionhijacking refers to an attacker impersonating a user by obtaining the user's sessionID. Prevention methods include: 1) encrypting communication using HTTPS; 2) verifying the source of the sessionID; 3) using a secure sessionID generation algorithm; 4) regularly updating the sessionID.

What is the full form of PHP?What is the full form of PHP?Apr 28, 2025 pm 04:58 PM

The article discusses PHP, detailing its full form, main uses in web development, comparison with Python and Java, and its ease of learning for beginners.

How does PHP handle form data?How does PHP handle form data?Apr 28, 2025 pm 04:57 PM

PHP handles form data using $\_POST and $\_GET superglobals, with security ensured through validation, sanitization, and secure database interactions.

What is the difference between PHP and ASP.NET?What is the difference between PHP and ASP.NET?Apr 28, 2025 pm 04:56 PM

The article compares PHP and ASP.NET, focusing on their suitability for large-scale web applications, performance differences, and security features. Both are viable for large projects, but PHP is open-source and platform-independent, while ASP.NET,

Is PHP a case-sensitive language?Is PHP a case-sensitive language?Apr 28, 2025 pm 04:55 PM

PHP's case sensitivity varies: functions are insensitive, while variables and classes are sensitive. Best practices include consistent naming and using case-insensitive functions for comparisons.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software