301,302 都是HTTP狀態的編碼,都代表着某個URL發生了轉移。不同之處就是:
301 redirect: 301代表永久性轉移(Permanently Moved),301重定向是網頁更改地址後對搜索引擎友好的最好方法,只要不是暫時搬移的情況,都建議使用301來做轉址。(推薦使用)
302 redirect: 302代表暫時性轉移(Temporarily Moved ),在前些年,不少Black Hat SEO曾廣泛應用這項技術作弊,目前,各大主要搜索引擎均加強了打擊力度,象Google前些年對Business.com以及近來對BMW德國網站的懲罰。即使網站客觀上不是spam,也很容易被搜尋引擎容易誤判爲spam而遭到懲罰。
meta fresh: 這在2000年前比較流行,不過現在已很少見。其具體是通過網頁中的meta指令,在特定時間後重定向到新的網頁,如果延遲的時間太短(約5秒之內),會被判斷爲spam。
<meta http-equiv="refresh" content="0;url=http://forum.csdn.net" />
PHP下的301重定向
<?
Header( "HTTP/1.1 301 Moved Permanently" ) ;
Header( "Location:
http://www.bloghuman.com
" );
?
ASP下的301重定向
<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","
http://www.csdn.net
"
%>
ASP .NET下的301重定向
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader ("Location","
http://www.csdn.net
");
}
</script>
ColdFusion下的301重定向
<.cfheader statuscode="301" statustext="Moved permanently">
<.cfheader name="Location" value="
http://www.csdn.net
">