我创建了一个具有不同参数的重写规则
add_rewrite_rule(
'^shop/(\b(thanks)\b)/([0-9]+)/([0-9]+)$',
'index.php?pagename=shop&shop_endpoint=$matches[1]&ref=$matches[2]&key=$matches[3]',
'top'
);
add_filter('query_vars', function($vars){
$vars[] = 'shop_endpoint';
$vars[] = 'ref';
$vars[] = 'key';
return $vars;
}, 10, 1);
我有以下网址 https://www.example.com/shop/thanks/2956789/6212/
如果我倾倒
get_query_var('schop_endpoint');
get_query_var('ref');
get_query_var('key');
输出是
而不是
我没有看到错误,谁可以帮助我一点?
我认为问题是
\b
存在于您的正则表达式中,这导致整个输出为 thanks
。
更正代码:
add_rewrite_rule(
'^shop/(thanks)/(\d+)/(\d+)$',
'index.php?pagename=shop&shop_endpoint=$matches[1]&ref=$matches[2]&key=$matches[3]',
'top'
);
add_filter('query_vars', function($vars){
$vars[] = 'shop_endpoint';
$vars[] = 'ref';
$vars[] = 'key';
return $vars;
}, 10, 1);
此外,为了简单起见,我已将
[0-9]
更改为 \d
(正如@mickmackusa 在问题评论中所建议的那样)。
希望这有帮助。