rewrite與location Nginx重寫功能( 四 )


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重寫功能

文章插圖
(2)瀏覽器訪問測試
rewrite與location Nginx重寫功能

文章插圖

rewrite與location Nginx重寫功能

文章插圖
【rewrite與location Nginx重寫功能】

推薦閱讀