在汤姆的建议下,我设法把它修好了。这就是我尝试的解决方案。
function product_perma_Rewrite() {
$prodCat = [\'taxonomy\' => \'product_cat\'];
$categories = get_categories($prodCat);
$catSlug = [];
foreach($categories as $category) {
$catSlug[] = $category->slug;
}
add_rewrite_rule(
\'^(\'.implode(\'|\', $catSlug).\')/([^/]+)/comment-page-([0-9]{1,})/?$\',
\'index.php?post_type=product&category=$matches[1]&product=$matches[2]&cpage=$matches[3]\',\'top\'
);
add_rewrite_rule(
\'^(\'.implode(\'|\', $catSlug).\')/([^/]*)/?\',
\'index.php?post_type=product&category=$matches[1]&product=$matches[2]\',
\'top\'
);
flush_rewrite_rules();
}
add_action(\'init\', \'product_perma_Rewrite\');