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:
website.com/search/something+searched
will go to the following
website.com/?s=something+searched
I have tried the following rewrite rule within the 'init' action.
add_rewrite_rule('^search/([^/]*)/$','?search=true&s=$matches[1]','top');
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.
Cheers
Noel