我有一个特定分类中自定义帖子类型的存档页面。这可以通过在taxonomy-[custom_taxonomy_slug].php
我的存档页面的结束网址是http://mysite.con/taxonomy/term/?post_type=post_type
我希望编写一个htaccess规则,允许我的网址读取/taxonomy/term/post_type/
,而不是包含查询参数。另外,Nginx上的等价物是什么?
到目前为止,我尝试过这样的事情,没有运气:
RewriteRule ^([^/]*)$ /taxonomy/term/?post_type=$1 [L]
但我对正则表达式或htaccess重写真的不太好,所以难怪它不起作用。
答案 0 :(得分:1)
您不需要htaccess规则,需要使用WordPress重写API添加新的重写规则。
function yourplugin_custom_rewrite() {
add_rewrite_rule("^taxonomy/([^/]+)/([^/]+)",'index.php?post_type=$matches[2]&taxonomy=$matches[1]','top');
}
add_action('init','yourplugin_custom_rewrite');
将“分类法”替换为您的自定义分类标本,它将完成这项工作。