asp,asp.net,php,jsp下的301转向代码
asp,asp.net,php,jsp下的301转向代码详细介绍
做网站的朋友偶尔会用到301转向,所以脚本之家站长特整理asp,asp.net,php,jsp下的301转向代码
使用.ht文件来进行301重定向,请见我的另外一篇文章《301重定向,域名更换后跳转到新域名》
。
如果空间不支持.ccess文件,那么我们还可以通过/代码来进行301重定向。
为了将搜索引擎的记录更新到现在的域名上面,做了几个301重定向的东东,给大家分享一下.
asp 301转向代码
在 index.asp 或 default.asp 的最顶部加入以下几行:
代码
如下:
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","//www.jb51.net/"
Response.End
%>
php 301转向代码
在 index.php 的最顶部加入以下几行:
代码如下:
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: //www.jb51.net/");
exit();
?>
301转向代码
代码如下:
<%@ Page Language="" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
HttpContext.Current.Response.StatusCode = 301;
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", "//www.jb51.net");
}
</script>
301代表永久性转移(Permanently Moved),301重定向是更改地址后对搜索引擎友好的最好方法,只
要不是暂时搬移的情况,都建议使用301来做转址。
下的301重定向
代码如下:
<%@ page language="" pageEncoding="GBK"%>
<%
response.setStatus(response.SC_MOVED_PERMANENTLY);
response.addHeader("Location",
http://"http://www.7hinet.com");
%>
可以通过filter控制需要重向的路径或页面
本文标题: asp,asp.net,php,jsp下的301转向代码 ,