我找到了解决问题的方法,但一点也不优雅
在Wordpress解析请求之前,我通过直接设置$\\u服务器[\'request\\u URI\'],确保解析的请求与重定向的请求相同
然后在Wordpress完成解析后,我将$\\u服务器[\'REQUEST\\u URI\']重置回其原始值<一点也不漂亮,但至少黑客的工作方式符合我的要求。如果有人能告诉我做这件事的“正确方法”,我仍然对答案感兴趣。。。
下面是我的“黑客”
add_filter(\'do_parse_request\', \'myplugin_doParseRequestFilter\', 10, 3);
add_filter(\'request\', \'myplugin_doRequestFilter\', 10, 1 );
function myplugin_doParseRequestFilter($some_bool, $request, $vars){
//called before Wordpress starts the parsing...
if(isset($_SERVER[\'REDIRECT_URL\'])){
if(strpos($_SERVER[\'REDIRECT_URL\'],\'/_my_page_prefix_/\')){
global $resetUrl;
$resetUrl=$_SERVER[\'REQUEST_URI\'];
$_SERVER[\'REQUEST_URI\']=$_SERVER[\'REDIRECT_URL\'];
}
}
return $request;
}
function myplugin_doRequestFilter($vars){
//called when Wordpress is finished parsing...
if(isset($_SERVER[\'REDIRECT_URL\'])){
if(strpos($_SERVER[\'REDIRECT_URL\'],\'/_my_page_prefix_/\')){
global $resetUrl;
$_SERVER[\'REQUEST_URI\']=$resetUrl;
}
}
return $vars;
}