301跳转

今天碰到一个很有意思的链接,在地址栏输入这个链接以后,按回车,这个链接会跳到百度的首页。于是找了一下资料,发现是301重定向。

index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="refresh" content="2;url=http://www.baidu.com/" />

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>正在进入百度,请稍等</title>

</head>

 

<body>

</body>

</html>

 

解释一下:我只在本地写了一个index.html的文件代码如上所示,在地址栏输入file:///E:/temp/index.html然后就跳转到了www.baidu.com.

其实只需要在<head>标签里添加一个<meta http-equiv="refresh" content="2;url=http://www.baidu.com/" />标签即可。

content="2,content标签表示经过几秒后跳转;url=http://www.baidu.com/"表示要跳转到的网址。

猜你喜欢

转载自www.cnblogs.com/banma/p/9068800.html
301