什麼是301跳轉?如何做301重新導向?

來源:互聯網
上載者:User

301跳轉和301重新導向是同一個意思兩種說法。

什麼是301跳轉?

如何做301跳轉

各種環境下重新導向實施代碼

IIS 重新導向

 

ColdFusion 重新導向

<.cfheader statuscode="301" statustext="Moved permanently">
<.cfheader name="Location" value="http://www.new-url.com"> 

PHP 重新導向

<?
Header( "HTTP/1.1 301 Moved Permanently" ); 
Header( "Location: http://www.new-url.com" ); 
?> 

ASP 重新導向

<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.new-url.com/"
%> 

ASP .NET 重新導向

<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.new-url.com");
}
</script> 

JSP (Java) 重新導向

<%
response.setStatus(301);
response.setHeader( "Location", "http://www.new-url.com/" );
response.setHeader( "Connection", "close" );
%> 

CGI PERL 重新導向

$q = new CGI;
print $q->redirect("http://www.new-url.com/"); 

Ruby on Rails 重新導向

def old_action
headers["Status"] = "301 Moved Permanently"
redirect_to "http://www.new-url.com/"
end 

老網域名稱重新導向到新網域名稱(htaccess 重新導向)

使用下面代碼建立 .htaccess 檔案,這將確保所有的目錄和您的舊域的網頁會得到正確重新導向到新網域名稱。htaccess檔案需要放在您的舊網站的根目錄下。

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

請替換www.newdomain.com為您實際網域名稱。

除了重新導向,我建議你通知夥伴修改連結並重新連結到您的新網站。

註:此重新導向(htaccess檔案)方法只有在Linux伺服器上使用apache並啟用 Apache Mod-Rewrite才有效。

 

重新導向 到www (htaccess redirect)

使用下面代碼建立 .htaccess 檔案, 這將確保所有的請求從domain.com 重新定向到 www.domain.com 
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

請替換www.newdomain.com為您實際網域名稱。

註:此重新導向(htaccess檔案)方法只有在Linux伺服器上使用apache並啟用 Apache Mod-Rewrite才有效。

 

 

重新導向偵查工具

http://www.webconfs.com/redirect-check.php

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.