zoukankan      html  css  js  c++  java
  • nginx rewrite 基础

    、跳转到首页

     如果请求的页面不存在的话就跳转到首页

     location / {

         if (!-e $request_filename){

           rewrite ^/(.*) /index.php last;

         }

     }

      

    二、地址跳转

    格式:

    rewirte  要跳转的页面      跳转的目标页面

     

    例子:

    rewrite a.html http://192.168.3.10/b.html last;

     

    要跳转的页面:a.html

    跳转的目标页面:b.html

    注意:跳转的目标页面必须写"全路径":比如以下

    http://192.168.3.10/b.html

     

     

    实例:

    echo " <h1>ye mian 1</h1> " > a.html

    echo " <h1>ye mian 2</h1> " > b.html

     

    vim /usr/local/nginx/conf/nginx.conf

    修改43行下的内容

            location / {

                 root   /web/benet;

                 index  index.html index.htm;

                 if (!-e $request_filename){

                 rewrite ^/(.*) /index.html last;

                 }

               rewrite a.html http://192.168.3.10/b.html last;

             }

     

    测试:

    访问不存在的页面,会自动跳转到首页

    访问a.html会自动跳转到b.html

  • 相关阅读:
    find the most comfortable road
    Rank of Tetris
    Segment set
    Codeforces Round #380 (Div. 2)D. Sea Battle
    A Bug's Life
    Is It A Tree?
    N皇后问题
    符号三角形
    2016 ICPC总结
    Sudoku Killer
  • 原文地址:https://www.cnblogs.com/pangbing/p/6957076.html
Copyright © 2011-2022 走看看