我想将搜索网址更改为漂亮的网址
搜索网址示例:
http://example.com/office-search/?real_country=singapore&real_city=any
漂亮的网址如:
http://example.com/office-search/singapore/any
我还写了一条重写规则,但它对我不起作用:
function search_url_rewrite_rule() {
if (is_search() && !empty($_GET['real_country']) || !empty($_GET['real_city']) || !empty($_GET['real_district'])) {
$c = $_GET['real_country'];
$city = $_GET['real_city'];
$district = $_GET['real_district'];
wp_redirect( home_url("/office-search/?".$c."/".$city."/".$district) . urlencode( get_query_var('real_country') ) );
exit();
};
}
add_action('template_redirect', 'search_url_rewrite_rule');