Rewrite the search results slug to /search/term

Adding this snippet to the functions.php of your wordpress theme will rewrite the search results URL to /search/ that will give you a results URL like http://wpsnipp.com/search/searchterm

 

 

function search_url_rewrite_rule() {
if ( is_search() && !empty($_GET['s'])) {
wp_redirect(home_url("/search/") . urlencode(get_query_var('s')));
exit();
}
}
add_action('template_redirect', 'search_url_rewrite_rule');

Leave a comment