0

我正在创建具有永久结构的 wordpress 博客:/postname.html 我必须为这篇文章制定另一个重写规则:/firstLetterOfTitle/postname.html 这两个规则都必须起作用,首先是默认永久链接。

我在我的主题functions.php中添加了代码:

add_rewrite_rule('^([a-z])/([a-zA-Z0-9\-\_]+)\.html$', '$matches[2]', 'top');

不幸的是它不起作用。有任何想法吗?

编辑:正如巴巴尔所说,应该是

add_rewrite_rule('/([a-z])/([a-zA-Z0-9\-\_]+)\.html$', '/index.php?pagename=$matches[2]', 'top');

4

1 回答 1

1

尝试这个:

add_rewrite_rule('/([a-z])/([a-zA-Z0-9\-\_]+)\.html$', '/index.php?p=$matches[2]', 'top');

(未测试)

并记住在添加此代码后手动刷新 WordPress 重写规则。(通过重新保存永久链接设置。)

更新(仅供说明)它应该是这样的:

add_rewrite_rule('/([a-z])/([a-zA-Z0-9\-\_]+)\.html$', '/index.php?pagename=$matches[2]', 'top');
于 2013-05-12T20:37:47.993 回答