DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁SEO優化 >  >> SEO相關 >> SEO優化
301重定向完整教程:IIS、ASP、PHP、Apache全平台設置方法
編輯:SEO優化     

所謂重定向,說白了就是把各種網絡請求重新指向另一個地址。做SEO時,301(永久重定向)常用於URL規範化與域名遷移。下面介紹在各主流環境下如何實現301重定向。

1、IIS下設置301

Internet信息服務管理器 -> 虛擬目錄 -> 重定向到URL,填入目標URL,並勾選「資源的永久重定向」。

2、ASP下的301轉向代碼

  1. <%@ Language=VBScript %>
  2. <%
  3. Response.Status=”301 Moved Permanently”
  4. Response.AddHeader “Location”, “https://www.sem.cm/2011/03/19/how-to-do-a-301-redirect/”
  5. %>

3、ASP.Net下的301轉向代碼

  1. <script runat=”server”>
  2. private void Page_Load(object sender, System.EventArgs e)
  3. {
  4. Response.Status = “301 Moved Permanently”;
  5. Response.AddHeader(”Location”,”https://www.sem.cm/2011/03/19/how-to-do-a-301-redirect/“);
  6. }
  7. </script>
  8. ?>

4、PHP下的301轉向代碼

  1. header(”HTTP/1.1 301 Moved Permanently”);
  2. header(”Location: https://www.sem.cm/2011/03/19/how-to-do-a-301-redirect/”);
  3. exit();
  4. ?>

5、CGI Perl下的301轉向代碼

  1. $q = new CGI;
  2. print $q->redirect(”https://www.sem.cm/”);
  3. ?>

6、JSP下的301轉向代碼

  1. <%
  2. response.setStatus(301);
  3. response.setHeader( “Location”, “https://www.sem.cm/” );
  4. response.setHeader( “Connection”, “close” );
  5. %>
  6. ?>

7、Apache下301轉向代碼

新建.htaccess文件,輸入下列內容(需開啟mod_rewrite):

1)將不帶WWW的域名轉向到帶WWW的域名:

  1. Options +FollowSymLinks
  2. RewriteEngine on
  3. RewriteCond %{HTTP_HOST} ^kuankuan.cn [NC]
  4. RewriteRule ^(.*)$ https://www.sem.cm/$1 [L,R=301]

2)重定向到新域名:

  1. Options +FollowSymLinks
  2. RewriteEngine on
  3. RewriteRule ^(.*)$ https://www.sem.cm/$1 [L,R=301]

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

  1. Options +FollowSymLinks
  2. RewriteEngine on
  3. 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配置如下:

  1. <VirtualHost *:80>
  2. ServerName www.kuankuan.cn
  3. DocumentRoot /home/kuankuan
  4. </VirtualHost>
  5.  
  6. <VirtualHost *:80>
  7. ServerName kuankuan.cn
  8. RedirectMatch permanent ^/(.*) https://www.sem.cm/$1
  9. </VirtualHost>

Apache下除以上兩種方法外,還有其他配置與可選參數,建議查閱官方文檔。

301轉向情況檢測

https://www.seoconsultants.com/tools/headers.asp
https://www.internetofficer.com/seo-tool/redirect-check/

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved