Hi, I try to change this url http://www.55555.com/?s=&cp_state=word to this http://www.55555.com/word I try to add a sting like this in functions.php function fb_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', 'fb_change_search_url_rewrite' ); Code (markup): but give me a url like this: http://www.55555.com/search/ instead of this http://www.55555.com/word Can you help me please to make this work? Thank you in advance for your help.
Hi, I tested the above code and it is working fine, with /search/word you might need to look at your template search code? as you are getting the following s=&cp_state=word, which should be ?s=word&submit=Search I hope it helped you a bit.
Thank you for your help but it doesen't work I need a url result like this http://www.55555.com/word and with the above code I have a result like this http://www.55555.com/search/ Thank you
Because of the SEO plugin I think it is difficult to have this way, even if you remove /search/ it takes to first matched search result. What is wrong with /search/word... or you can just replace /search/ with /s/ Hope it helped a bit
TRY THIS ONE The following example shows that even if you have permalinks activated, that the URL for the two search terms wordpress and consulting looks like this: bueltge.de/?s=wordpress+consulting&submit=Search. With a little function, which communicates with the redirect, you can adjust the URL. In my case the URL with the two searchterms look like this with the following function: bueltge.de/search/wordpress+consulting. Within WP-function wp_redirect I set the output, that the term search will be added to the home-url of your installation and added by the searchterms. There are many possibilities to adjust the URL. function fb_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', 'fb_change_search_url_rewrite' ); Yes, it is also possible via htacces rules, but the source is an example for custom solutions on an redirect. # search redirect # this will take anything in the query string, minus any extraneous values, and turn them into a clean working url RewriteCond %{QUERY_STRING} \\?s=([^&]+) [NC] RewriteRule ^$ /search/%1/? [NC,R,L] I would recommend to put the function in a Plugin or in the functions.php of your theme. Any other or better ideas to accomplish this? Please let us know in the comment area.