Wordpress 网站进行 301 重定向

对于一些虚拟主机、空间,没办法通过自行修改 rewrite 来进行 301 重定向,虽然题目是写着对于 wordpress 网站有效果,但其实这个方法对于任何搭建了 wordpress 网站的空间 / VPS / 服务器都通用。

以下方法亲测有效果,因为本博客就换过多次域名(blog.haizhistu.com->haizs.com)。

在需要跳转的旧 wordpress 网站的 wp 安装目录下打开 < span style=“color:#0000FF;”>wp-blog-header.php, 在 < span style=“color:#000099;”> 后加入

if (strtolower($_SERVER['SERVER_NAME'])!='haizs.com')
{
$URIRedirect=$_SERVER['REQUEST_URI'];
$URIRedirect=&quot;/&quot;;
/* 如果不想更改输入的页面链接的话将 $URIRedirect=&quot;/&quot;; 改为
if(strtolower($URIRedirect)==&quot;/index.php&quot;)
{
    $URIRedirect=&quot;/&quot;;
}
*/
header('HTTP/1.1 301 Moved Permanently');
header('Location:http://haizs.com'.$URIRedirect);
exit();
}