我有这个URL:
example.com/products-and-services/?catID=5我想让它变成这样:
example.com/products-and-services/5基本上,我删除了?catID=
以下是我用add_rewrite_rule编写的代码,我目前还没有成功:
function custom_rewrite_products() {
    add_rewrite_rule('products-and-services/([^/]+)/?$', 
    'index.php?pagename=products-and-services&catID=$matches[1]', 'top');
}
add_action('init', 'custom_rewrite_products')有什么建议吗?
发布于 2017-08-16 07:16:20
试一试:
function custom_rewrite_products() {
    add_rewrite_rule(
        '^products-and-services/([^/]*)/?$',
        'index.php?pagename=products-and-services&catID=$matches[1]',
        'top'
    );
}
add_action( 'init', 'custom_rewrite_products' );更多详细信息请访问:https://wordpress.stackexchange.com/questions/250837/understanding-add-rewrite-rule
发布于 2017-08-16 13:06:15
使用这个。
function custom_rewrite_tags() {
    add_rewrite_tag('%catID%', '([^&]+)');
}
add_action('init', 'custom_rewrite_tags', 10, 0);
function custom_rewrite_products() {
    add_rewrite_rule('^products-and-services/([\w+]*)/', 'index.php/?pagename=products-and-services&catID=$matches[1]', 'top');
}
add_action('init', 'custom_rewrite_products');https://stackoverflow.com/questions/45702221
复制相似问题