一、. 重定向(Redirect)就是通過各種方法將各種網絡請求重新定個方向轉到其它位置(如:網頁重定向、域名的重定向、路由選擇的變化也是對數據報文經由路徑的一種重定向)。
二、
1.網站調整(如改變網頁
目錄結構);
2.網頁被移到一個新地址;
3.網頁擴展名改變(如應用需要把.php改成.Html或.shtml)。
這種情況下,如果不做重定向,則用戶收藏夾或搜索引擎數據庫中舊地址只能讓訪問客戶得到一個404
頁面錯誤信息,訪問流量白白喪失;再者某些注冊了多個域名的網站,也需要通過重定向讓訪問
這些域名的用戶自動跳轉到主
站點等。
三、常用的重定向方式有:
301 redirect-----永久性轉移
302 redirect-----暫時性轉移
四、Apache服務器實現301重定向
相比較來說,Apache實現起來要比IIS簡單多了。在Apache中,有個很重要的文件.htaccess,通過對它的設置,可以實現很多強大的功能,
301重定向只是其中之一。
Redirect permanent / http://www.bloghuman.com/ (將目錄下內容重定向到http://www.bloghuman.com/ )
redirect permanent /index.php http://www.bloghuman.com/index.php?go=category_6(將網頁index.php重定向到http://www.bloghuman.com/index.php?go=category_6)
通過合理地配置重定向參數中的
正則表達式,可以實現更復雜的匹配。有興趣的朋友可參考本站Apache手冊。
PHP下的
301重定向
<?php
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.bloghuman.com"
%>
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.bloghuman.com");
}
</script>
ColdFusion下的301重定向
<.cfheader statuscode="301" statustext="Moved permanently">
<.cfheader name="Location" value="http://www.new-url.com">