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:
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]
(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);
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.