簡體   English   中英

WordPress URL重寫規則

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM