且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

wordpress - 将 url 查询字符串转换为静态

更新时间:2023-02-23 09:16:23

您的规则缺少最后的 ? 使最后一个斜杠成为可选.添加问号后,您的重定向应该可以工作.函数调用将如下所示:

Your rule is missing the final ? to make the last slash optional. After adding the question mark, your redirect should work. The function call will look like this:

add_rewrite_rule('^conversations/([0-9]+)/?', 'index.php?page_id=3242&cid=$matches[1]', 'top');

此外,每次您在 Wordpress 中以编程方式创建新的重写规则、使用重写函数或添加自定义帖子类型时,例如,您都需要刷新永久链接.为此,只需转到 WP 管理员中的永久链接设置页面,然后点击保存按钮.这足以刷新规则.

Also, every time you programmatically create new rewrite rules in Wordpress, using rewrite functions or when adding custom post types, for instance, you need to flush the permalinks. To do so, simply go to permalink settings page in your WP admin and hit the save button. This will be enough to flush the rules.