zoukankan      html  css  js  c++  java
  • 301和302的区别

    一、来看看官方的说法:

      301,302 都是HTTP状态的编码,都代表着某个URL发生了转移,不同之处在于: 
      301 redirect: 301 代表永久性转移(Permanently Moved)。
      302 redirect: 302 代表暂时性转移(Temporarily Moved )。

    其实301、302的重定向都是通过对http协议的location的修改来实现的,那具体的怎么去修改location来实现重定向呢?

    1.通过php的header函数去实现这个请求

    <?php
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: http://www.baidu.com/");
    ?>

    如图:

      

    如果写成下面这样,就是302了,与上图对比一下

    <?php
    header("Location: http://www.baidu.com/");
    ?>

    如图:

      

    也就是说,如果你在header函数内不标明的话,默认是302

    重定向的原理:就是对http报文的location的修改(一般我们都是去web服务器上面做重定向操作的)

    nginx有一个location指令,它可以修改http报文的location

    咱们先看一张静态页面访问如图:

      

      这里显示200,并没有出现location标签和信息,此时我们可以在nginx中加入这么一句话(设置301的方法):

          location ~ .html$ {
                   rewrite ^(.*).html$ $1.php permanent;
           }

      

      下面是设置302的方法:

        location ~ .html$ {
                   rewrite ^(.*).html$ $1.php redirect;
        }

      

     

  • 相关阅读:
    hdu2063:过山车
    牛客网:ph试纸
    牛客网:石子阵列
    最短路
    POJ1067:取石子游戏
    实现DataGridView实时更新数据
    SendMessage API
    使用Intel IPT技术保护您的帐号安全
    它是对 ACME(automated certificate management environment) 协议的实现,只要实现了 ACME 协议的客户端都可以跟它交互。
    time out 超时
  • 原文地址:https://www.cnblogs.com/xsj1/p/10966002.html
Copyright © 2011-2022 走看看