網站301轉向代碼大全

來源:互聯網
上載者:User

1、IIS下301設定

Internet資訊服務管理器 -> 虛擬目錄 -> 重新導向到URL,輸入需要轉向的目標URL,並選擇"資源的永久重新導向"。

2、ASP下的301轉向代碼

<%@ Language=VBScript %> <% Response.Status="301 Moved Permanently" Response.AddHeader "Location", "http://www.mydomain.cn/" %>

3、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.mydomain.cn/articles/301/"); } </script>

4、PHP下的301轉向代碼

header("HTTP/1.1 301 Moved Permanently"); header("Location: http://www.mydomain.cn/articles/301/"); exit();

5、CGI Perl下的301轉向代碼

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

6、JSP下的301轉向代碼

<% response.setStatus(301); response.setHeader( "Location", "http://www.mydomain.cn/" ); response.setHeader( "Connection", "close" ); %>

7、Apache下301轉向代碼

建立.htaccess檔案,輸入下列內容(需要開啟mod_rewrite):

1)將不帶WWW的網域名稱轉向到帶WWW的網域名稱下

Options +FollowSymLinks RewriteEngine on RewriteCond %{HTTP_HOST} ^mydomain.cn [NC] RewriteRule ^(.*)$ http://www.mydomain.cn/$1 [L,R=301]

2)重新導向到新網域名稱

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

3)使用正則進行301轉向,實現偽靜態

Options +FollowSymLinks RewriteEngine on RewriteRule ^news-(.+)\.html$ news.php?id=$1

將news.php?id=123這樣的地址轉向到news-123.html

8、Apache下vhosts.conf中配置301轉向

為實現URL正常化,SEO通常將不帶WWW的網域名稱轉向到帶WWW網域名稱,vhosts.conf中配置為:

<VirtualHost *:80> ServerName http://www.mydomain.cn/ DocumentRoot /home/lesishu </VirtualHost>

<VirtualHost *:80> ServerName mydomain.cn RedirectMatch permanent ^/(.*) http://www.mydomain.cn/$1 </VirtualHost>

參考資料: 老北京農家院(http://www.bj1568.com/)
鴻石網際(http://www.hungstone.cn/)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.