## url rewriting – How to change search page url so that it still returns a page when there’s no search query specified?

Question

I want to change the search url of WordPress. Instead of url.com/?s=searchterm I want to change it to url.com/search/searchterm or url.com/search?s=searchterm.

On Google there’s plenty of solutions for this, but most boil down to the following:

function wpb_change_search_url() {
if ( is_search() && ! empty( \$_GET['s'] ) ) {
wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) );
exit();
}
}

This works nice, but there’s one caveat: if I open the page url.com/search,it gives me an error message. Whilst in the old situation url.com?s= gave me a page with ‘type your query to search this search’, now it gives a now found.
So my question is: how do I modify the above code, so that the page /search/ returns the same page as with an empty ?s=?