rewrite与location Nginx重写功能( 五 )


用浏览器访问 http://www.fzr.com/100-200-100.html 或 http://www.fzr.com/100-100-100.html 跳转到http://www.fzr.com页面
4.4.2 实例操作:基于参数匹配的跳转
(1)修改配置文件

rewrite与location Nginx重写功能

文章插图

rewrite与location Nginx重写功能

文章插图

rewrite与location Nginx重写功能

文章插图
(2)浏览器访问测试
rewrite与location Nginx重写功能

文章插图

rewrite与location Nginx重写功能

文章插图
4.5基于目录下所有 php 结尾的文件跳转要求访问 http://www.fzr.com/upload/123.php 跳转到首页 。
4.5.1 基于目录下所有 php 结尾的文件跳转的操作步骤
vim /usr/local/nginx/conf/nginx.confserver {    listen       80;    server_name  www.fzr.com;        #域名修改    charset utf-8;    access_log  /var/log/nginx/www.fzr.com-access.log  main;    location ~* /upload/.*\.php$ {        rewrite (.+) http://www.fzr.com permanent;    }    location / {        root   html;        index  index.html index.htm;    }}systemctl restart nginx浏览器访问 http://www.fzr.com/upload/888.php 跳转到http://www.fzr.com页面 。4.5.2 实例操作:基于目录下所有 php 结尾的文件跳转
(1)修改配置文件
rewrite与location Nginx重写功能

文章插图

rewrite与location Nginx重写功能

文章插图

rewrite与location Nginx重写功能

文章插图
(2)浏览器访问测试
rewrite与location Nginx重写功能

文章插图

rewrite与location Nginx重写功能

文章插图
4.6基于最普通一条 url 请求的跳转要求访问一个具体的页面如 http://www.fzr.com/abc/888.html 跳转到首页
4.6.1 基于最普通一条 url 请求的跳转的操作步骤
vim /usr/local/nginx/conf/nginx.confserver {    listen       80;    server_name  www.fzr.com;        #域名修改    charset utf-8;    access_log  /var/log/nginx/www.fzr.com-access.log;    location ~* ^/abc/888.html {        rewrite (.+) http://www.fzr.com permanent;    }    location / {        root   html;        index  index.html index.htm;    }}systemctl restart nginx浏览器访问 http://www.fzr.com/abc/888.html 跳转到http://www.fzr.com页面 。4.6.2 实例操作:基于最普通一条 url 请求的跳转
(1)修改配置文件
rewrite与location Nginx重写功能

文章插图

rewrite与location Nginx重写功能

文章插图

rewrite与location Nginx重写功能

经验总结扩展阅读