Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The principle and implementation of Rewrite Jump

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

This article will introduce the jump principle and implementation method of Rewrite in detail. The detailed steps are clear and the details are handled properly. I hope you can gain something through this article. Let's first take a look at the jump principle of Rewrite:

Rewrite jump scenario URL looks more standardized. Reasonable enterprises will disguise dynamic URL addresses as static addresses to provide service URLs for new domain names, and then allow the old access to be redirected to the new domain names. Some business adjustment Rewrite jump implementation on the server

The implementation of Nginx Jump requirement in Rewrite practical scenario

Use rewrite for matching jumps

Jump after matching global variables with if

Use location matching and then jump rewrite to match domain names or parameter strings in server {}, if {}, location {} segments

Use if global variable matching

Use the regular expression metacharacters commonly used by proxy_pass reverse agents to describe ^ match the start position of the input string $match the end position of the input string * match the previous character zero or more times + match the previous character one or more times? Matches the preceding character zero or once. Match any single character except\ n, using a pattern such as "[.\ n]" Can match any character, including "\ n",\ d match pure number [0-9] {n} repeat {n,} repeat n or more times [c] match a single character c [a-z] match any [a-zA-Z] of the lower case letter of Amurz or any Rewrite command syntax of the uppercase letter of Amurz: rewrite [flag] Flag tags supported by rewrite for content after regular jump

The flag tag says:

The tag indicates that last is equivalent to the [L] tag of Apache, indicating that the completion of rewritebreak will be terminated upon completion of the matching of this rule. Redirect will no longer match any of the following rules. Redirect returns 302 temporary redirection, the browser address will display the jumped URL address, the crawler will not update the urlpermanent and return 301 permanent redirection, the browser address bar will display the jumped URL address, and the crawler will update the url.

Last and break comparison:

Lastbreak usage scenarios are generally written in server and if generally use URL matching in location to match url matching after non-terminating rewriting url matching location classification after termination rewriting: location = patt {} [precise matching] location patt {} [General matching] location ~ patt {} [regular matching]

Common expressions for regular matching:

The tag says ~ to perform a regular match, case sensitive ~ * to perform a regular match, not case sensitive! ~ perform a regular match, case-sensitive mismatch! ~ * performs a regular match, case-insensitive, case-insensitive, ^ ~ normal character matching; uses prefix matching. If the match is successful, the exact match of other location= normal characters is no longer matched. That is, exact match @ defines a named location, using expressions of the same type location priority in internal orientation, long characters will first match * sort by priority * * = type ^ ~ type expression regular expression (~ and ~ *) type regular string match type, usually match (/) by prefix match, if there is no other match Any request will be matched to compare the similarities between rewrite and location** can be redirected * * different points * * rewrite is to change the path to get resources within the same domain name location is to control access or direction proxy for a class of paths You can also proxy_pass to other machines * * rewrite will write the execution order in location * * execute rewrite instructions in server block execute location match execute rewrite instructions in selected location location priority example # # exact match /, hostname cannot be followed by any string location = / {[configuration A]} # # all addresses begin with /, this rule will match all requests However, regular and longest strings first match location / {[configuration B]} # # matches any address that begins with / documents/, and location / documents/ {[configuration C]} # # matches any address that begins with / documents/abc when the subsequent regular expression does not match, and when the subsequent regular expression does not match Location ~ / documents/abc {[configuration D]} # # addresses starting with / images/. After matching, stop matching location ^ ~ / images/ {[configuration E]} # # match all requests ending in gif, and images under / images/ will be processed by [configuration E] because ^ ~ has a higher priority location ~ *\. (gif | jpg | jpeg) ${[configuration F]} # # longest character matches to / images/abc Lowest priority location / images/abc {[configuration G]} # # priority location ~ / images/abc {[configuration H]} # # if compared with regular ~ / images/abc/1.html, regular priority is higher location / images/abc/1.html {[configuration I]} location priority rule

Match a specific file:

(location = full path) > (location ^ ~ full path) > (location ~ full path) > (location ~ full path) > (location full path) > (location /)

Access a file with a directory match:

(location = directory) > (location ^ ~ directory /) > (location ~ directory) > (location ~ directory) > (location directory) > (location /)

After reading the above, do you have a general understanding of the jump principle and implementation of Rewrite? If you want to know more about the content of the article, welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report