StackOverflow上有许多关于如何实现这一点的有用线程,但这里有一个小的WP解决方案,您可以在不修改.htaccess
文件:
add_action(\'init\', function() {
$redirect_to_domain = \'google.com\'; // without protocol
$https = false; // redirect to https ( default: http )
// don\'t change the following unless you know what you\'re doing
$domain = str_replace( array(\'http://\', \'https://\'), \'\', get_site_url() );
$uri = $_SERVER[\'HTTP_HOST\'] . $_SERVER[\'REQUEST_URI\'];
wp_redirect( ( $https ? "https://" : "http://" ) . str_replace( $domain, $redirect_to_domain, $uri ) );
exit;
});
记住,在执行重定向之前,WordPress仍将被启动。
希望这有帮助。