我写了一个简单的快捷码,并在我的图库页面上使用它。页面的URL如下所示:
http://mysite.dev/gallery/?view=category-name
但我想能够使用http://mysite.dev/gallery/category-name
当我使用这样的URL时,WP会重定向到它能找到的最接近的匹配项。例如http://mysite.dev/gallery/nature
重定向到http://mysite/home/nature
我尝试实施重写规则:function add_custom_rewrites()
{
remove_filter(\'template_redirect\', \'redirect_canonical\');
add_rewrite_rule(\'^gallery/([^/]*)/?$\', \'index.php/gallery/?category=$matches[1]\', \'top\');
add_rewrite_tag(\'%category%\', \'(.+)\');
flush_rewrite_rules();
}
add_action(\'init\', \'add_custom_rewrites\');
但是/gallery/category页面总是重定向到try,并通过某种方式找到最近的匹配页面。有人能帮忙吗?