1

I want to redirect search result page to a static page like example.com/?s=searchterms to example.com/searchterms or example.com/?s=searchterms to example.com/searchterms.html

Any possibility in wordpress I am able to redirect example.com/?s=searchterms to example.com/search/searchterms

1 Answer 1

1

Write this in your theme's functions.php. Hope this helps you out.

function code_search() {
    if ( is_search() &&
         strpos($_SERVER['REQUEST_URI'], '/wp-admin/') === false &&
         strpos($_SERVER['REQUEST_URI'], '/search/') === false ) {
         wp_redirect( get_bloginfo('home') . '/search/' . str_replace(' ', '_', str_replace('%20', '_', get_query_var('s'))));
         exit();
    }
}

add_action('template_redirect', 'code_search');
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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