Http 请求头Location跳转方式的请求转发

webview的自定义SSL认证配置(p12证书)


我们知道,某些情况下由于网站迁移,权限,页面错误时我们可能需要跳转页面到错误页面,如

1.HTTP/1.1 404 Not Found

2.HTTP/1.1 301 Moved Permanently

3.HTTP/1.1 302 Moved Temporarily


但是我们发送响应码只是一种状态机制,因此往往我们需要选择合适的跳转方式,Location跳转是一种常见的方式,特别对于做SEO的同学来说

下面我们通过php语言来说明(结果与编程语言无关)


index.php

<?php
header('HTTP/1.1 301 Moved Permanently'); 
Header( "Location: http://192.168.1.98/result.php?".$_SERVER['QUERY_STRING'] ); 
exit();

result.php

<?php
$arr = [];

$arr['name'] = 'zhangsan';
$arr['age'] = 20;
echo json_encode($arr);

?>

当我们访问http://192.168.1.98/index.php?st=123ABC时,发生了如下转换

Request-1

GET /test/ HTTP/1.1
Host: localhost
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36
Content-Type: text/plain; charset=utf-8
Accept: */*
Accept-Encoding: gzip, deflate, sdch
Accept-Language: zh-CN,zh;q=0.8,en;q=0.6

RedirectTo

HTTP/1.1 301 Moved Permanently
Date: Sun, 30 Aug 2015 09:59:14 GMT
Server: Apache/2.4.9 (Win32) PHP/5.5.12
X-Powered-By: PHP/5.5.12
Location: http://localhost/test/result.php
Content-Length: 0
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html

Request-2

GET /test/ HTTP/1.1
Host: localhost
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36
Content-Type: text/plain; charset=utf-8
Accept: */*
Accept-Encoding: gzip, deflate, sdch
Accept-Language: zh-CN,zh;q=0.8,en;q=0.6

responseTo

HTTP/1.1 200 OK
Date: Sun, 30 Aug 2015 09:59:14 GMT
Server: Apache/2.4.9 (Win32) PHP/5.5.12
X-Powered-By: PHP/5.5.12
Content-Length: 28
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: text/html

响应体

{"name":"zhangsan","age":20}


总结:

在这个过程中Request-1与Request-2相同,也就是说Location在跳转的时候同样将请求进行了转发,在这一过程中,一个请求被传递了2次,跳转的过程中并未改变客户端连接,只是服务器端进行了跳转,整个过程是完整的,所以Location使得http请求过程具有完整性和连续性


使用方向:

1.SEO优化,固定重定向

2.请求转发跳转

3.权限检测,拦截,重要文件下载(先判断权限,然后跳转到文件链接,类似某视频网站的)


转载于:https://my.oschina.net/ososchina/blog/499242

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值