您的位置:首页 > Web前端 > JavaScript

asp,asp.net,php,jsp下的301转向代码

2008-09-23 14:04 926 查看
使用.htaccess文件来进行301重定向,请见我的另外一篇文章《301重定向,域名更换后跳转到新域名》

如果空间不支持.htaccess文件,那么我们还可以通过php/asp代码来进行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();
?>

asp.net 301转向代码
复制代码 代码如下:
<%@ Page Language="C#" %>
<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来做转址。

JSP下的301重定向
复制代码 代码如下:
<%@ page language="java" pageEncoding="GBK"%>
<%
response.setStatus(response.SC_MOVED_PERMANENTLY);
response.addHeader("Location","http://www.7hinet.com");
%>

可以通过filter控制需要重向的路径或页面

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  网站 301转向