Page jump is realized by Nginx's map instruction
- 2020-05-12 06:50:13
- OfStack
preface
This article mainly introduces the use of Nginx
map
Instruction to achieve page jump method, there is a need for the following 1 to learn to learn.
Implementation method
In nginx. conf
http
Domain to add
map
Instruction rule, which contains 1 URL rule mapping file:
# Set up the 301 jump
map $request_uri $new {
include /etc/nginx/redirect.map;
}
map
The directive supports the introduction of a mapping file, where the content format of redirect.map file is as follows:
~^/page/mordern-php$ /page/modern-php;
So far only 1 line has been added as a test, which can be preceded by a regular expression and followed by the new URL to jump to, each line ending with a semicolon.
Since the website has opened HTTPS, it is listening on port 443
server
Block,
location
Add rules before statement as follows:
if ($new) {
rewrite ^ https://www.tanteng.me$new redirect;
}
This statement indicates that if URL matches the rule in redirect.map, it jumps to the new URL rule.
Restart the nginx service and you'll see the results.
conclusion
Well, the above is the use of Nginx map command to achieve page jump all the content, this function is relatively practical for everyone, I hope this article can help people in need, if you have questions you can leave a message to communicate.