我强烈建议不要使用IIS,在WordPress中实现您的要求:
/**
* Remove category base from "newcat" permalink.
*
* @param string $link
* @param object $term
* @return string
*/
function wpse_175424_term_link( $link, $term ) {
if ( $term->taxonomy === \'category\' && $term->slug === \'newcat\' )
$link = home_url( user_trailingslashit( $term->slug ) );
return $link;
}
add_filter( \'term_link\', \'wpse_175424_term_link\', 10, 2 );
/**
* Add our custom rewrite rule to the top of category rules.
*
* @param array $rules
* @return array
*/
function wpse_175424_category_rewrite_rules( $rules ) {
global $wp_rewrite;
$matches_1 = $wp_rewrite->preg_index( 1 );
$new_rules = array(
\'newcat/feed/(feed|rdf|rss|rss2|atom)/?$\' => "$wp_rewrite->index?category_name=newcat&feed=$matches_1",
\'newcat/(feed|rdf|rss|rss2|atom)/?$\' => "$wp_rewrite->index?category_name=newcat&feed=$matches_1",
\'newcat/page/?([0-9]{1,})/?$\' => "$wp_rewrite->index?category_name=newcat&paged=$matches_1",
\'newcat/?$\' => "$wp_rewrite->index?category_name=newcat",
);
return $new_rules + $rules;
}
add_filter( \'category_rewrite_rules\', \'wpse_175424_category_rewrite_rules\' );
添加代码后,需要刷新重写规则(只需访问设置>永久链接页面即可)。
注意,我已经硬编码了newcat
在这两个功能中,如果您需要灵活使用;由ID/选项拉动,这很容易。