在WordPress中重写URL不适用于此场景

在WordPress中重写URL不适用于此场景,wordpress,mod-rewrite,url-rewriting,Wordpress,Mod Rewrite,Url Rewriting,我一直试图在wordpress中重写这个特定的规则,看起来很简单,但我无法让它工作 Current url: topic/?topic_id=155&title=life-balance 及 我对url重写知之甚少,这是我第一次重写url。这就是我尝试过的 在functions.php文件中 add_action( 'init', 'add_seourl_rules' ); function add_seourl_rules() { add_rewrite_rule(

我一直试图在wordpress中重写这个特定的规则,看起来很简单,但我无法让它工作

Current url: topic/?topic_id=155&title=life-balance

我对url重写知之甚少,这是我第一次重写url。这就是我尝试过的

functions.php文件中

add_action( 'init', 'add_seourl_rules' );
function add_seourl_rules() { 
    add_rewrite_rule(
        "topic/([^/]+)/([^/]+)/?",
        "topic/?topic_id=$matches[1]&title=$matches[2]",
        "top");
}
添加此函数后,我重新保存了永久链接以刷新URL,但它仍然不起作用

*Step 1:* 
你知道我做错了什么吗。 谢谢

编辑1: 好的,我已经做了这些更改,但仍然不起作用

*Step 1:* 
我的永久链接在WP永久链接中设置为%%postname%%。我把它们改回正常(?p=123)

到目前为止,我的正常页面和帖子都回到了普通URL

normal pages: example.com/?page_id=717

normal posts: example.com/?p=2470

custom post: example.com/?page_id=717&topic_id=155&title=life-balance


***`Step 3`***
为了重写我的自定义帖子url,我将我的函数更改为

add_action( 'init', 'add_seourl_rules' );
function add_seourl_rules() { 
    add_rewrite_rule(
        '^topics/([^/]+)/([^/]+)/?',
        'index.php?page_id=717&topic_id=$matches[1]&title=$matches[2]',
        'top');
}

仍然无法使其适用于自定义帖子,也不确定我应该为我的正常页面和帖子做些什么

在永久链接部分,你的wp重写规则是什么?它被设置为post name。你现在的规则是错误的。。第一条规则应该与您当前的url(topic/?topic\u id=155&title=life balance)匹配,然后重写为所需的(topic/155/life balance)复选框。。好吧,我明白你的意思,但如果我想让所有其他页面和帖子以类似于wp postname permalink的方式显示,并且只想为我的自定义帖子编写这种url,那该怎么办?例如,我的postname permalink显示了这样一个页面url(www.example.com/pagename),但对于这个自定义帖子,我希望我的url是(www.example.com/155/postname)?您确实应该在www.example.com/之后添加一些数字以外的内容。使用一些入口点,如www.example.com/custom/155/postname,并制定规则来检查“custom”单词..以及permalink部分中的wp重写规则是什么?它设置为post name。您现在的规则是错误的。。第一条规则应该与您当前的url(topic/?topic\u id=155&title=life balance)匹配,然后重写为所需的(topic/155/life balance)复选框。。好吧,我明白你的意思,但如果我想让所有其他页面和帖子以类似于wp postname permalink的方式显示,并且只想为我的自定义帖子编写这种url,那该怎么办?例如,我的postname permalink显示了这样一个页面url(www.example.com/pagename),但对于这个自定义帖子,我希望我的url是(www.example.com/155/postname)?您确实应该在www.example.com/之后添加一些数字以外的内容。使用一些入口点,如www.example.com/custom/155/postname,并制定规则检查“custom”单词。。
add_action( 'init', 'add_seourl_rules' );
function add_seourl_rules() { 
    add_rewrite_rule(
        '^topics/([^/]+)/([^/]+)/?',
        'index.php?page_id=717&topic_id=$matches[1]&title=$matches[2]',
        'top');
}