回諸彼特租屋資訊網首頁 - 租屋,租房子,租屋網站,房屋出租  諸彼特租屋網 - 外包工作網站(外包,家教,工讀,正職)
首頁 查詢租屋 網上資料 租屋地圖 簡介 帳號 出租房子 維護租屋資料 委託追蹤 討論區 各項統計 網站目錄 網站地圖
[會員登入|註冊]

[WEB][PHP][SEO] 轉導、轉向(Redirect)網址的方法.

at 2010 年 09 月 04 日 08:03:16 Sat,瀏覽頁次:504966
看板:JJDai 顯示模式設定:遞減→遞增 | 群組→非群組文章, 不能/無權限 回覆此文章
|< << 上一頁 [1] 下一頁 >> >|
此文章群組總共有 4 編文章,以下為 1 - 4  [第1頁]:
標題:[WEB][PHP][SEO] 轉導、轉向(Redirect)網址的方法.
作者:jjdai (jjdai)
時間:2007-02-15 03:20:36
來源:61.230.202.101

此文:
點閱:32979
回覆:3

[WEB][PHP][SEO] 轉導、轉向(Redirect)網址的方法



在將網站更換成新網址的情況下,可能會在舊網址上使用到一些『轉導網址』的方法,以便將原本的使用者及其流量引導到新的網址去。

以下整理、討論到幾種轉導(Redirect)網址的技術方法,並且探討該方法對 SEO 的影響:

1. 使用 HTTP 通訊協定 301 Moved Permanently 來完成轉導網址 (永久轉址)

    (建議使用,不會對 SEO 有不良影響)

o PHP 程式範例:
<?php
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: http://www.new-url.com/");
?>
<p>The document has moved <a href="http://www.new-url.com/">here</a>.</p>


    註1:
  1. 使用者的瀏覽器必須根據 HTTP header 的 Location 欄位值(稱做URI)來轉導網址。

  2. 註2:
  3. 除非 Request Method 是 HEAD,不然伺服器端回覆的訊息內必須包含一短的新網址的連結(hyperlink)資訊。



o ASP 程式範例:
<%@ Language=VBScript %>
<%
    Response.Status="301 Moved Permanently"
    Response.AddHeader "Location", " http://www.new-url.com/"
    Response.End
%>
<p>The document has moved <a href="http://www.new-url.com/">here</a>.</p>


o 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>
<p>The document has moved <a href="http://www.new-url.com/">here</a>.</p>


o 在 .htaccess / httpd.conf 檔案中設定 -- 轉整個 domain
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*) http://www.new-domain.com/$1 [R=301,L]


o 在 .htaccess / httpd.conf 檔案中設定 -- 轉到新的 www.
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{http_host} ^old-domain.com [NC]
RewriteRule ^(.*)$ http://www.new-domain.com/$1 [R=301,NC]


2. 使用 HTTP/1.1 通訊協定 302 Found 來完成轉導網址

    (建議使用,會對新網站 SEO 有不良影響)

o PHP 程式範例:
<?php
    header("HTTP/1.1 302 Found");
    header("Location: http://www.new-url.com/");
?>
<p>The document has moved <a href="http://www.new-url.com/">here</a>.</p>


(...其他 ASP, ASP.NET 程式及設定 .htaccess/httpd.conf 方法,此處略 ...)

    註1: 302,
  1. 在 HTTP/1.0 是『Moved Temporarily』;HTTP/1.1 是『Found』,會根據 HTTP header 的 Location 欄位值(稱做URI)來轉導網址。但是很多網路上的文章會直接稱 302 是 Moved Temporatily。

  2. 註2:
  3. 除非 Request Method 是 HEAD,不然伺服器端回覆的訊息內必須包含一短的新網址的連結(hyperlink)資訊。

  4. 註3:
  5. HTTP 1.1 中增訂了 『307 Temporary Redirect』,307 碼時只會根據 GET Request 轉導網址。

  6. 註4:
  7. 更多的 HTTP 302 細節和 307 會被再增訂出來的原因請參考這裡


3. HTML 的 refresh meta tag 來轉導網址

    (非常不建議使用,會對新網站 SEO 有不良影響。有些文章寫說要用時最好秒數設定大於 10 秒以避免對頁面的 SEO 不利。)

o 在 HTML 檔案的 HEAD 中,範例:
<html>
<head>
    <meta http-equiv="refresh" content="0;url=http://www.new-url.com/" />
</head>


4. 用 JavaScript 來達到轉導網址 (放在 HTML 的 <head>...</head> 或 <body>...<body> 中

    (因為搜尋引擎的 bot 一般都不理會 JavaScript,所以做什麼動作不會被檢查。這意味著要實做『點擊計算(click counting)後再轉導到目的網址的話,用這個方法比較好(302 或 refresh 都是不好的方法)』)
    (如果使用者按瀏覽器的『上一頁』按鈕,不會跳回轉導頁面。)

o 直接在 HTML 的 HEAD 中用轉導網址 JavaScript 範例:
<html>
<head>
<script language="JavaScript">
<!--
    window.location.replace("http://www.new-url.com");
//-->
</script>
</head>
</html>


o JavaScript 內容同上例,但是把它放到外部的一個 .js 檔案,然後 <head>...</head> 中只要寫:
<html>
<head>
    <script language="JavaScript" src="redirect.js"></script>
</head>


o 也是使用 JavaScript,但是額外透過『表單』來完成:

    (因為搜尋引擎的 bot 一般都不理會『表單』,所以做什麼動作不會被檢查。)

<script language="JavaScript">
<!--
    document.myform.submit();
//-->
</script>
<form name="myform" action="http://www.new-url.com/" method="get"></form>




額外討論:

  1. 301/302 有時會被一些人用作旁門走道方法,在玩『PR劫持』(如這篇文章所述),更多的一些手法討論請看這篇文章或用 hijack 當 KeyWord 去查查。

  2. 302 在之前會造成 bot 誤以為是轉導到的網站在惡搞,而將轉導到的網站從索引中除名。所以會變得無法防止別人以此方法攻擊自己的 URL。現或許已更正。(詳情請看這裡)

  3. 當然,refresh 也能如上述 302 一樣去惡搞別人的網站。



這篇文章的關鍵字(Keyword): http redirection, http redirect head, http redirects, http redirect html, http redirect example, http redirect meta, redirect script, redirect php, redirect javascript, html refresh page, html redirection, html redirect page, 301 redirect, 302 redirect


--
jjdai
(C) http://rental.zhupiter.com | zhupiter@gmail.com
序號:#1.
設定屬性  | 搬移文章  | 刪除文章  | 修改文章  | 回應此文章

標題:Re: [WEB][PHP][SEO] 轉導、轉向(Redirect)網址的方法.
作者:jjdai (jjdai)
時間:2010-02-15 23:46:44
來源:61.230.83.102
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

[Informational 1xx]
100="Continue"
101="Switching Protocols"

[Successful 2xx]
200="OK"
201="Created"
202="Accepted"
203="Non-Authoritative Information"
204="No Content"
205="Reset Content"
206="Partial Content"

[Redirection 3xx]
300="Multiple Choices"
301="Moved Permanently"
302="Found"
303="See Other"
304="Not Modified"
305="Use Proxy"
306="(Unused)"
307="Temporary Redirect"

[Client Error 4xx]
400="Bad Request"
401="Unauthorized"
402="Payment Required"
403="Forbidden"
404="Not Found"
405="Method Not Allowed"
406="Not Acceptable"
407="Proxy Authentication Required"
408="Request Timeout"
409="Conflict"
410="Gone"
411="Length Required"
412="Precondition Failed"
413="Request Entity Too Large"
414="Request-URI Too Long"
415="Unsupported Media Type"
416="Requested Range Not Satisfiable"
417="Expectation Failed"

[Server Error 5xx]
500="Internal Server Error"
501="Not Implemented"
502="Bad Gateway"
503="Service Unavailable"
504="Gateway Timeout"
505="HTTP Version Not Supported"
序號:#2.
設定屬性  | 搬移文章  | 刪除文章  | 修改文章  | 回應此文章

標題:Re: [WEB][PHP][SEO] 轉導、轉向(Redirect)網址的方法.
作者:jjdai (jjdai)
時間:2009-04-27 23:49:25
來源:114.32.231.245
在 apache 的 httpd-vhosts.conf 設定轉導 (redirect)

<VirtualHost 61.62.63.64:80>
    ServerName zhupiter.com
    Redirect 301 / http://www.zhupiter.com/
</VirtualHost>

適用於一個 IP 多個 domainname 一起用的主機。

(Modified by [jjdai] from 114.32.231.245 at 2009-04-27 23:50:14)
序號:#3.
設定屬性  | 搬移文章  | 刪除文章  | 修改文章  | 回應此文章

標題:Re: [WEB][PHP][SEO] 轉導、轉向(Redirect)網址的方法.
作者:jjdai (jjdai)
時間:2009-04-23 23:41:47
來源:122.116.236.55
Source: http://tw.php.net/header

 Dylan at WeDefy dot com
13-Oct-2007 03:17
A quick way to make redirects permanent or temporary is to make use of the $http_response_code parameter in header().

// 301 Moved Permanently
header("Location: /foo.php",TRUE,301);

// 302 Found
header("Location: /foo.php",TRUE,302);
header("Location: /foo.php");

// 303 See Other
header("Location: /foo.php",TRUE,303);

// 307 Temporary Redirect
header("Location: /foo.php",TRUE,307);
?>

The HTTP status code changes the way browsers and robots handle redirects, so if you are using header(Location:) it's a good idea to set the status code at the same time. Browsers typically re-request a 307 page every time, cache a 302 page for the session, and cache a 301 page for longer, or even indefinitely. Search engines typically transfer "page rank" to the new location for 301 redirects, but not for 302, 303 or 307. If the status code is not specified, header('Location:') defaults to 302.

序號:#4.
設定屬性  | 搬移文章  | 刪除文章  | 修改文章  | 回應此文章
|< << 上一頁 [1] 下一頁 >> >|

 | 

Google
 


Display Page Rank
諸彼特租屋資訊網 - 租屋,租房子,租屋網站,房屋出租

諸彼特租屋資訊網

版權所有 (C) 1999-2010 Dai Juin-Jia. All Rights Reserved. Since 2000/04/06Company Logo - 諸彼特租屋資訊網
Powered by DjLibPhp