2015-11-16 126 views
0

我想創建一個WordPress的自定義頁面有一個特殊的URL重寫,我想以下幾點:自定義重寫規則在WordPress的

function custom_rewrite_rule() { 
add_rewrite_rule('^services/service-in-([^/]*)/?','index.php?page_id=238&location=$matches[1]','top'); 
    } 
    add_action('init', 'custom_rewrite_rule'); 

然而,當我去domain.com/services/service -in-london /我只是收到了404消息。

我也試過這個手動htaccess,但只得到404

回答

0

你能請嘗試以下代碼

function custom_rewrite_rule() { 
    add_rewrite_tag('%location%', '([^/]*)'); 

    add_rewrite_rule('^services/([^/]*)/?$', 'index.php?page_id=238&location=$matches[1]', 'top'); 
    flush_rewrite_rules(); 
} 

add_action('init', 'custom_rewrite_rule');