在做web开发中,页面跳转的方式有很多种,然而有些时候这些跳转如何用到恰到好处却很容易被忽视。
触发跳转有如下几种
- 使用meta元信息
|
2.使用javascript中的window.location对象
|
补充一点:在html5中,利用新的api实现前端页面mvc的跳转也是一种不错的方式(注意:服务端不跳转),利用这种方式可以实现前端MVC开发
|
以上是客户端触发的跳转
-------------------------------------------------------------------------------------------
触发的跳转的方式
- php中使用header跳转
|
推荐使用下面的方式
|
有时,设置http 响应头是非常重要的,这些可以帮助搜索引擎和浏览器“理解”请求的状态
下面提供一种发送http响应头的php函数
|
然后我们来优化一下
1 2 | |
问题来了:这里挖掘机技术必须强,使用http响应后需要注意的是,在响应头发送之前必须没有输出流输出内容,因此,这种让人满意的方法有时并不适用;下面进行改造:
|
当然有时候会出现n秒后跳转过渡页面,这个也不是很困难,但这种重定向只需默认的“临时重定向”就行,避免SEO权值转移。
|
--------------------------------------------------------------------------------
在页面有2个红色的词语“触发”,这里的意思是通过触发事件来进行跳转的,在http请求中(http基于tcp连接),一般是 “请求-应答”模式,但这种模式是独立于页面跳转的。
实际上页面跳转分为2中方式 :客户端跳转,客户端和服务端一起跳转
客户端跳转在目前mvc主流框架中使用较为广泛,这种跳转一般通过服务端控制(Controller)触发,如j2ee servlet中的Dispatcher和forward以及php中的include,display,客户端和服务端一起跳转一般具有强制性,这个无论前端和后端均可使用,但后端使用的一个好处是可以发送状态码,对于SEO等工作具有很多好处。