[英]WordPress URL Rewrite Rules
我有這個網址:
example.com/products-and-services/?catID=5
我想要這樣:
example.com/products-and-services/5
基本上我要刪除?catID=
這是我的add_rewrite_rule
代碼, 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')
有什么建議么?
試試看:
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
用這個。
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');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.