Answers:
您可以使用该parse_request
操作来完成此操作。只需在您的主博客上启用此插件即可。将以下代码放在.php文件中,并将其上传到您的插件目录。
/*
Plugin Name: Redirect Main Site To Sub-Site
Description: Redirect 'main-site' to 'main-site/sub-site/'
Version: 0.1
Author: WPSE
Author URI: http://wordpress.stackexchange.com
License: GPL2
*/
add_action('parse_request', 'redirect_to_sub_site');
function redirect_to_sub_site(){
global $wp;
#Sniff requests for a specific slug
if('main-site' === $wp->request){
#The URL to redirect TO
$url = 'http://www.example.com/main-site/sub-site/';
#Let WordPress handle the redirect - the second parameter is obviously the status
wp_redirect($url, 301);
#It's important to exit, otherwise wp_redirect won't work properly
exit;
}
}
如果您有任何问题,请告诉我。