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

  • 相关阅读:
    流程控制-分支结构
    nginx配置详解
    git/github初级使用
    svn基本使用详情
    windows下搭建SVN服务器
    Linux下搭建svn服务器
    构建源码
    swipe实现app滑动效果
    app测试专项(摘抄自网络)
    新版本覆盖安装升级后,微信登陆提示获取openid失败
  • 原文地址:https://www.cnblogs.com/pangbing/p/6957076.html
Copyright © 2011-2022 走看看