保持推荐的最佳方法是从服务器发出标准 301。
如何使用.htaccess执行此操作
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !newdomain.com$ [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]
直接从 PHP 执行它也应该有效(正如DaveRandom所指出的),只要确保包含 HTTP 响应代码。
<?php
// 301 Moved Permanently
header("Location: http://siteb.com/somepage", TRUE, 301);
下面是一张表格,其中包含来自不同重定向方式的数据及其对分析的影响。
Redirect method | Browser | Result | Impact on analytics
----------------------------+-----------+-------------------+--------------------
Meta refresh - 0 | Firefox 3 | Blank referrer | Lost data
| IE8 | Blank referrer | Lost data
| Opera 9 | Internal referrer | Lost data
Javascript:location.href | Firefox 3 | Internal referrer | Lost data
| IE8 | Blank referrer | Lost data
| Opera 9 | Internal referrer | Lost data
Javascript:location.replace | Firefox 3 | Internal referrer | Lost data
| IE8 | Blank referrer | Lost data
| Opera 9 | Internal referrer | Lost data
Server-side 301 | Firefox 3 | Original referrer |
| IE8 | Original referrer |
| Opera 9 | Original referrer |
Server-side 302 | Firefox 3 | Original referrer |
| IE8 | Original referrer |
| Opera 9 | Original referrer |
Server-side 301 - chained | Firefox 3 | Original referrer |
| IE8 | Original referrer |
| Opera 9 | Original referrer |
Server-side 302 - chained | Firefox 3 | Original referrer |
| IE8 | Original referrer |
| Opera 9 | Original referrer |
上表的原始链接。