Wordpress url重写到post permalink

Wordpress url重写到post permalink,wordpress,url-rewriting,Wordpress,Url Rewriting,我正在创建wordpress博客,它具有permaling结构:/postname.html 我必须为这篇文章制定另一条重写规则:/firstLetterOfTitle/postname.html 这两个规则都必须起作用,首先作为默认永久链接 我在theme functions.php中添加了代码: add_rewrite_rule('^([a-z])/([a-zA-Z0-9\-\\\\\\+)\.html$,'$matches[2]','top') 不幸的是,它不起作用。有什么想法吗 编辑:

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

我在theme 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')

尝试以下操作:

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');

它不起作用:-(我在添加重写规则后调用
flush\u rewrite\u rules();
。很抱歉,应该是这样的:
add\u rewrite\u rule('/([a-z])/([a-zA-Z0-9\-\\\\\+)\.html$,'/index.php?pagename=$matches[2],'top');
您可以试试这个。