301重定向不但可以在Apache服務(wù)器或者IIS中配置,也可以使用代碼的形式來做301重定向,而且方法很簡單,這里icech整理了一個各種語言編寫的301重定向代碼給大家,各取所需吧!
PHP 301 重定向代碼
301重定向也可以在php文件中通過加入php header來實現(xiàn),代碼如下:
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: exit();
?>
ASP 301 重定向代碼
<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", http://farlee.info
%>
ASP.NET 301 重定向代碼
<script language="c#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location",http://farlee.info);
}
</script>
ColdFusion 301 重定向代碼
<.cfheader statuscode="301" statustext="Moved permanently"> CGI Perl下的301轉(zhuǎn)向代碼 $q = new CGI; JSP下的301轉(zhuǎn)向代碼 <%
<.cfheader name="Location" value="
print $q->redirect("
response.setStatus(301);
response.setHeader( "Location", " response.setHeader( "Connection", "close" );
%>