【问题标题】:Wordpress rewrite rule not working?Wordpress 重写规则不起作用?
【发布时间】:2017-05-14 13:53:58
【问题描述】:

我正在尝试在 wordpress 网站上实施一些重写规则来重写我的网址,例如:

词汇表/?terms=a

词汇表/术语/a

我已将以下代码添加到我的 functions.php 并刷新了重写但没有运气?

add_rewrite_rule('^glossary/([0-9]+)/?', 'glossary/?terms=$matches[1]', 'top');

谁能指出我正确的方向或告诉我上面有什么不正确的地方?

【问题讨论】:

  • [0-9] 匹配“包含一个数字”,例如 /?id=4。您使用的是 ID 还是文本(示例 'a' 表示字符串,因此必须匹配字符串)。

标签: php wordpress mod-rewrite url-rewriting


【解决方案1】:

设法使它与以下重写规则一起工作:

add_rewrite_rule('^glossary/term/([a-z]+)/page/([0-9]+)/?$', 'index.php?post_type=glossary&terms=$matches[1]&paged=$matches[2]', 'top');

【讨论】:

    猜你喜欢
    • 2013-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-13
    • 2015-01-31
    • 2015-09-01
    • 2019-12-13
    • 2017-05-30
    相关资源
    最近更新 更多