How to use Nginx's map instruction to achieve page jump

WBOY
Release: 2023-05-15 17:16:12
forward
813 people have browsed it

Implementation method

Add map directive rules in the http domain of nginx.conf, which contains a url rule mapping file:

# 设置301跳转
map $request_uri $new {
 include /etc/nginx/redirect.map;
}
Copy after login

map The command supports the introduction of a mapping file. The content format of the redirect.map file here is as follows:

~^/page/mordern-php$ /page/modern-php;
Copy after login

Currently only one line is added as a test, the front can be Regular expression, followed by the new url to jump to, and each line ends with a semicolon.

Since the website has https enabled, in the server block that listens to port 443, add the following rule before the location statement:

if ($new) {
 rewrite ^ https://www.tanteng.me$new redirect;
}
Copy after login

This statement means If the url matches the rule in redirect.map, jump to the new url rule.

Restart the nginx service and you can see the effect.

The above is the detailed content of How to use Nginx's map instruction to achieve page jump. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!