HTTP返回码301与302的区别

一、简介

1、301,302 都是HTTP状态的编码,都代表着某个URL发生了转移。 
2、301 redirect: 301 代表永久性转移(Permanently Moved)。
3、302 redirect: 302 代表暂时性转移(Temporarily Moved )。
4、301,302对用户来说没有区别,他们看到效果只是一个跳转,浏览器中旧的URL变成了新的URL。页面跳到了这个新的url指向的地方。
5、不同之处,主要在于SEO优化,302好于301。

 

二、实现

1、PHP实现302跳转

源代码:

<?php
header("Location: http://yegle.net/recursion.php");
?>

HTTP头:

HTTP/1.1 302 Found
Date: Fri, 16 Jul 2010 11:26:48 GMT
Server: Apache
X-Powered-By: PHP/5.2.4-2ubuntu5.10
Location: http://yegle.net/recursion.php
Cache-Control: max-age=600
Expires: Fri, 16 Jul 2010 11:36:48 GMT
Vary: Accept-Encoding
Content-Length: 0
Content-Type: text/html

  

2、PHP实现301跳转

源代码:

<?php
header( "HTTP/1.1 301 Moved Permanently" );
header( "Location: http://yegle.net/" );
?>

HTTP头:

HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Fri, 16 Jul 2010 11:29:07 GMT
Expires: Sun, 15 Aug 2010 11:29:07 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 1; mode=block

 

  

 

转载于:https://www.cnblogs.com/gao88/p/6743047.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值