淘主机 发表于 2009-12-15 21:30:31

Godaddy空间的301转向代码合集【翻译】

本文翻译自Godaddy帮助中心:http://help.godaddy.com/article/234,同样适用于一般空间。
如果你需要对网站中的一些页面进行重新设计,原来的URL失效了,但你又想保证这个页面的搜索引擎排名,你就可以用301转向讲旧页面指向新的地址,301转向能够保证页面的权重完全从旧页面转向新页面。
通过301转向,搜索引擎蜘蛛将把旧页面的排名和外链统统转向新页面。因此,301转向又叫做“永久转向”(与之对应的有302暂时转向)。
比如,你能够把oldpage.php(.asp 或 .jsp)转向"http://www.newdomain.com/newpage.html",这样将保持搜索引擎排名和外链。
使用下面的代码进行301重定向:
(提示:下面的代码中,“oldpagename”替换成你的旧页面地址,“newpage.html”替换成新页面地址,也就是你想要转向的页面,“www.taohost.net”替换成你的域名)
1、PHP 301转向代码-将以下代码存为oldpagename.php
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.taohost.net/newpage.html");
exit();
?>
2、ASP 301转向代码-将以下代码存为oldpagename.asp
<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", "http://www.taohost.net"
%>

3、Coldfusion 301转向代码-将以下代码存为oldpagename.cfm
<.cfheader statuscode="301" statustext="Moved permanently">
<.cfheader name="Location" value="http://www.taohost.net/newpage.html">

4、ASP.NET 301转向代码-将以下代码存为oldpagename.aspx
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.taohost.net");
}

5、无www转向www(利用htaccess实现301转向)
当用的是Linux服务器,并且Apache Mod-Rewrite开启的时候,你可以在网站跟目录中创建.htaccess文件,通过.htaccess可以把所有对taohost.net的请求指向www.taohost.net, .htaccess 必须放在网站的根目录中,和你的主页文件在同一个文件夹内。请把下面的代码写入.htaccess中。
RewriteEngine on
rewritecond %{http_host} ^coolexample.com
rewriterule ^(.*)$ http://www.coolexample.com/$1

6、IIS中实现301重定向
如果用的是Windows主机,你能够用IIS实现301重定向
* 在the Internet Services Manager中,选择需要重定向的文件或文件夹
* 在右键菜单中,选择 a redirection to a URL
* 指定你需要转向的页面
* 选择The exact URL entered above
* 选择A permanent redirection for this resource
* 点击Apply
页: [1]
查看完整版本: Godaddy空间的301转向代码合集【翻译】