As the title suggests I am trying to create pretty permalinks for search queries, but unfortunately I cant get them to work.

I am trying to achieve the folllowing:


will go to the following


I have tried the following rewrite rule within the 'init' action.


This doesn't work, although 'website.com/search/something' will go to the search page but not pass the var. As does the below code:

function search_rewrite( $wp_rewrite ) {
    $feed_rules = array(
        'search/(.+)'    =>  'index.php?s='. $wp_rewrite->preg_index(1)
    $wp_rewrite->rules = $feed_rules + $wp_rewrite->rules;
// refresh/flush permalinks in the dashboard if this is changed in any way
add_filter( 'generate_rewrite_rules', 'search_rewrite' );

I believe I'm missing something on my search.php file but I'm not sure what.

Is there a reason for search queries / rewrites to behave differently to other rewrites?

Thanks in advance for any assistance.



  • If you pass the Query to s manually do results get returned w/o the permalinks?
    – eyoung100
    May 30, 2014 at 16:32
  • the search_rewrite function would be in my functions.php file. The add_rewrite_rule was in a must use plugin
    – noelmcg
    May 30, 2014 at 16:35
  • I reformed my comment after you saw it. Look again...
    – eyoung100
    May 30, 2014 at 16:39
  • Thats correct. If I manually query s the results get returned as normal without returning the permalinks. I am also flushing the permalinks.
    – noelmcg
    May 30, 2014 at 16:49
  • Your question is also here at the forums
    – eyoung100
    May 30, 2014 at 16:59

1 Answer 1


Schoolboy error!

I was using:


as opposed to:


Hence the empty search results.

Hope this might help somebody in the future!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.