Because you want to rewrite an address from
/MAG/XX/XXX/->/M/xxx
But the original/MAG/XX/more/should be retained
In this case, you have to write a strange regular expression. I have tried a lot of writing methods and I have not succeeded.
The first thing to think about is:
Location ~ * ^/MAG/[^/] +/[^ (more)] + /{
Rewrite ^/MAG/[^/] +/(. *)/M/$1 permanent;
}
[] Is not effective in writing. It matches a single character, which is invalid and cannot be matched.
I am still a good friend of fan. I have studied deeply and provided some non-certain words (?! More)
Location ~ * ^/MAG/[^/] + /(?! More) ([^/] + )/{
Rewrite ^/MAG/[^/] +/(. *)/M/$1 permanent;
}
This statement is barely enough. Although the matching unit is not perfect, it can also deal with all my requirements.
If necessary, refer to this method.
Common grouping syntax
Capture
(Exp) Match exp and capture the text to the automatically named group
(? Exp) Match exp, and capture the text to the group named name. You can also write (? 'Name' exp)
(? : Exp) matches exp, does not capture the matched text, and does not assign group numbers to this group.
Assertion with Zero Width
(? = Exp) match the position before exp
(? <= Exp) match the position behind exp
(?! Exp) the position behind the matching is not the exp position.
(? ...