我正在将3个不同的域(站点)与第4个集线器域合并。重定向数组中列出的重定向有效,但是通过Drupal CMS生成的垃圾页面没有任何价值(因此,没有重定向到中心域上的页面)。我想为/ junk-pages设置默认重定向。我还希望404错误显示在新的中心域404错误页面上,而不是显示在旧的域404错误页面上。
// Array of pages from old-domain.com redirected to relavant page on hubsite.com for site merger
$redirect_targets = array(
'/old-domain1' => 'https://hubsite.com/page-one',
'/old-domain2' => 'https://hubsite.com/page-two',
'/old-domain3' => 'https://hubsite.com/page-three',
);
if ( (isset($redirect_targets[ $_SERVER['REQUEST_URI'] ] ) ) && (php_sapi_name() != "cli") ) {
echo 'https://hubsite.com'. $_SERVER['HTTP_HOST'] . $redirect_targets[ $_SERVER['REQUEST_URI'] ];
header('HTTP/1.0 301 Moved Permanently');
header('Location: https://hubsite.com'. $_SERVER['HTTP_HOST'] . $redirect_targets[ $_SERVER['REQUEST_URI'] ]);
if (extension_loaded('newrelic')) {
newrelic_name_transaction("redirect");
}
exit();
}
// Any page from old-domain.com not listed in the array above goes to a default location on hubsite.com
// Any 404 error on old-domain.com goes to 404 error page on hubsite.com instead of old-domain.com