页面跳转

301转向(或叫301重定向,301跳转)是当用户或搜索引擎向网站服务器发出浏览请求时,服务器返回的HTTP数据流中头信息(header)中的状态码的一种,表示本网页永久性转移到另一个地址。
302重定向又称之为302代表暂时性转移(302 redirect/temporary redirect),一个暂时重定向是一种服 务器端的重定向
301重定向与302重定向的区别:

1、302重定向是暂时的重定向,搜索引擎会抓取新的内容而保留旧的网址。因为服务器返回302代码,搜索引擎认为新的网址只是暂时的。 SEO 302好于301

2、301重定向是永久的重定向,搜索引擎在抓取新内容的同时也将旧的网址替换为重定向之后的网址。 

前端实现

1.  html语法

<head>
<meta http-equiv="refresh" content="1;url=http://www.taobao.com">
</head>

content中1表示跳转的间隔时间1秒钟后挑转,0表示直接跳转。后面是具体要跳转的页面

2. js实现

<script>
  setTimeout(function () {
    location.href = 'http://www.taobao.com';
  }, 2000);
</script>

后端实现

nodejs实现的代码:

var connect = require('connect');

var app = connect();
app.use('/public', connect.static(__dirname + '/public'));
app.use('/redirect', function (req, res, next) {
  res.statusCode = 302;
  res.setHeader('Location', 'http://www.taobao.com');
  res.end();
});

 
If you want http://www.example.org/foo to actually display what's at http://www.example.org/bar you should not use "refresh" techniques like :
 
<META HTTP-EQUIV=REFRESH CONTENT="1; URL=http://www.example.org/bar">

Why? because it could break the "back" button. Imagine that the user presses the "back" button, the refresh would work again, and the user would bounce forward. The user will most likely get very annoyed, and close the window, which is probably not what you, as the author of this page, want.Use HTTP redirects instead 

参考:

https://www.w3.org/QA/Tips/reback

原文地址:https://www.cnblogs.com/chenlogin/p/5594387.html