Rewrite the search results slug to /search/term

Visual Composer Review

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')));
add_action('template_redirect', 'search_url_rewrite_rule');

Comments  Leave a Reply

  1. Luis Sacristán June 6, 2012 at 3:57 pm

    Thanks for the snipp, but there is a problem when you try to search words with accents (á, é, í, ó, ú) or others letters (ñ, ç, …)

    You have to decode the search term in the query_vars and in the search_query. Here is my code

    function you_search_filter($s) {
    return urldecode($s);

    add_filter(‘get_search_query’, ‘you_search_filter’);

    add_filter(‘the_search_query’, ‘you_search_filter’);

    add_action(‘parse_query’, ‘you_query_vars_search_filter’ );

    function you_query_vars_search_filter( $qvars ) {
    $qvars->query_vars[‘s’] = urldecode($qvars->query_vars[‘s’]);
    return $qvars;


    Hope it could be useful

  2. Is there some SEO advantage by using this instead of the default URL?
    Nice function BTW, i’ll use it.

    1. To be honest I don’t think it is that big of a help to SEO however if you have pretty links enabled this continues this look rather then ?s= .

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!