I'm having a problem with my Wordpress site when using search. This is probably due to qTranslate plugin.
So I have permalink turned on and when I use search field, I get URL with ?s= query string like this:
www.mydomain.com/en/?s=test
The above URL works just fine but if I have many search results that show pagination buttons, links on those buttons cause 404 errors. Link for second page has the following URL:
www.mydomain.com/en/page/2/?s=test
This throws 404 error but if I manually modify the URL like this:
www.mydomain.com/en/search/test/page/2/
then the pagination works.
So I would like to force Wordpress to use /search/ permalink instead of /?s= query string but not sure how to do that.
you can do it by the following function, paste this into your theme functions.php
function change_search_url_rewrite() {
if ( is_search() && ! empty( $_GET['s'] ) ) {
wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) );
exit();
}
}
add_action( 'template_redirect', 'change_search_url_rewrite' );
then the search url will be like search/test instead of ?s=test,this function is quit simple