我正在尝试使用以下.htaccess
更改搜索过滤器的 URL 结构:
/tours/?tour-type=guided&tour-destination=europe&tour-type=guided&tour-duration=17%2B&tour-season=2020
对此:
/tours/guided/europe/guided/17/2020
显然,搜索过滤器有许多不同的选项,例如日期,位置不同类型的等,我知道这在.htaccess
是可能的,但事实证明它对我来说是难以捉摸的。
在wordpress中,最好使用add_rewite_rule
函数。在下面的示例中,我假设 tours 是自定义帖子类型,因此post_type=tours
。你可以在那里放页面ID,类别slug或任何你想要的东西。 请注意,使用此规则,如果您只想发送巡演季节,则必须为其余变量发送一些内容。
function tour_add_rewrite_rules() {
add_rewrite_rule('^tours/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/?$', 'index.php?post_type=tours&tour-type=$matches[1]&tour-destination=$matches[2]&tour-type=$matches[3]&tour-duration=$matches[4]&tour-season=$matches[5]', 'top' );
}
add_action('init', 'tour_add_rewrite_rules', 10, 0);