|
|
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已! |
|
恭喜您是本站第 1729117
位訪客!
登入 | 註冊
|
|
|
|
發表者 |
討論內容 |
冷日 (冷日) |
發表時間:2008/11/3 8:06 |
- Webmaster

- 註冊日: 2008/2/19
- 來自:
- 發表數: 15771
|
- [轉貼][WEB][PHP][SEO] 轉導、轉向(Redirect)網址的方法
- [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 target="_blank" href="http://www.new-url.com/">here</a>.</p>
註1: 使用者的瀏覽器必須根據 HTTP header 的 Location 欄位值(稱做URI)來轉導網址。 註2: 除非 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 target="_blank" 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 target="_blank" 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 target="_blank" href="http://www.new-url.com/">here</a>.</p>
(...其他 ASP, ASP.NET 程式及設定 .htaccess/httpd.conf 方法,此處略 ...) 註1: 302, 在 HTTP/1.0 是『Moved Temporarily』;HTTP/1.1 是『Found』,會根據 HTTP header 的 Location 欄位值(稱做URI)來轉導網址。但是很多網路上的文章會直接稱 302 是 Moved Temporatily。 註2: 除非 Request Method 是 HEAD,不然伺服器端回覆的訊息內必須包含一短的新網址的連結(hyperlink)資訊。 註3: HTTP 1.1 中增訂了 『307 Temporary Redirect』,307 碼時只會根據 GET Request 轉導網址。 註4: 更多的 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 的 ... 或 ... 中 (因為搜尋引擎的 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 檔案,然後 ... 中只要寫:
<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>
--------------------------------------------------------------------------------
額外討論:
- 301/302 有時會被一些人用作旁門走道方法,在玩『PR劫持』(如這篇文章所述),更多的一些手法討論請看這篇文章或用 hijack 當 KeyWord 去查查。
- 302 在之前會造成 bot 誤以為是轉導到的網站在惡搞,而將轉導到的網站從索引中除名。所以會變得無法防止別人以此方法攻擊自己的 URL。現或許已更正。(詳情請看這裡)
- 當然,refresh 也能如上述 302 一樣去惡搞別人的網站。
原文出處:[WEB][PHP][SEO] 轉導、轉向(Redirect)網址的方法. - 諸彼特租屋網
|
|
冷日 (冷日) |
發表時間:2008/11/3 8:12 |
- Webmaster

- 註冊日: 2008/2/19
- 來自:
- 發表數: 15771
|
- [轉貼]網頁轉址(redirect)
- 網頁轉址(redirect)
--------------------------------------------------------------------------------
當你要將網頁搬家的時候,必須要十分小心,雖然說只要在原網址加上轉址(redirect)功能,一般訪客就可以順利進入你的新網頁,但如果小細節沒注意到,卻容易造成搜尋引擎的誤會,輕則舊網頁的排名無法順利轉移到新網頁,重則整個網站會被視為spam而遭封殺!
常用的轉址方式有三種: 301 redirect, 302 rediretc 以及 meta fresh.
301 redirect: 301代表永久轉址(permanently moved),這是對SEO最安全的轉址方式,只要不是暫時搬移的情況,都建議使用301來做轉址.
.htaccess作法:
網頁轉址
RedirectPermanent /old-file-name.html http: //www.new-domain.com/new-directory/new-file-name.html
目錄轉址
RedirectPermanent /old-directory http: //www.new-domain.com/new-directory/
全站轉址
RedirectPermanent / http: //www.new-domain.com/
php作法: PHP 代碼:
< ?php
header("Status: 301 Moved Permanently", false, 301);
header("Location: http://www.new-domain.com/new-directory/new-file-name.html");
exit();
?>
302 redirect: 302代表暫時轉址(temporary),容易被搜尋引擎容易誤判為spam而遭到懲罰.建議不要使用.
.htaccess作法:
網頁轉址
Redirect /file-name.html http: //www.domain.com/temporary-directory/temporary-file-name.html
目錄轉址
Redirect /directory http: //www.domain.com/temporary-directory/
全站轉址
Redirect / http: //www.temporary-domain.com/
php作法: PHP 代碼:
< ?php
header("Location: http://www.domain.com/temporary-address/temporary-file-name.html");
exit();
?>
meta fresh: 藉由網頁中的meta指令,於特定時間後重新導向到新的網頁,如果延遲的時間太短(約3秒之內),會被判斷為spam,若必須採用meta fresh的方式時,請勿將延遲時間設定太短.
HTML 代碼:
<HTML>
<HEAD>
…
<META HTTP-EQUIV=refresh" CONTENT="停留的秒數;URL=要轉的URL">
…
</HEAD>
<BODY>
…
</BODY>
</HTML>
原文出處:站長俱樂部 - 網頁轉址(redirect)
|
|
冷日 (冷日) |
發表時間:2012/11/4 12:55 |
- Webmaster

- 註冊日: 2008/2/19
- 來自:
- 發表數: 15771
|
- [分享]如何在送出網頁資料後自動將使用者重新導向新的頁面?
- 如何在送出網頁資料後自動將使用者重新導向新的頁面?
這個問題無法透過PHP本身解決,因為 header() 函數必須在所有資料送出之前使用;不過可以透過HTML的屬性或JAVASCRIPT等使用者端程式達到。
HTML,在標籤中加上下面這一行:
<meta http-equiv="refresh" content="5; URL=new_page.php">
JAVASCRIPT,方法很多,提供一個簡單的:
<body onLoad="setTimeout ("location.href='http://domain.com/page.html',5000");">
而 M$ 官方(參考點)提出的方法:
var version = navigator.appVersion;
// sets variable = browser version
if (version.indexOf("MSIE") != -1)
// checks to see if using IE
{
window.location.href="ie.htm"
/* If using IE, it shows this page
replace ie.htm with page name */
}else
window.open("other.htm", target="_self")
/* else open other page
replace other.html with page name */
或是這樣也可以:
<script language='JavaScript'>window.location.replace('http://domain.com/page.html');</script>
可以參閱: [分享]那,改採Java Script轉址吧!
|
|
|