0

How can I change the search URL from /?s=my-word to /busca/?s=my-word ?

I know how to change to /busca/my-word, but I really need the "s" parameter.

Thanks.

1 Answer 1

0

From WPEngineer (with edits):

Add the following to functions.php in your theme:

function fb_change_search_url_rewrite() {
    if ( is_search() && ! empty( $_GET['s'] ) ) {
        wp_redirect( home_url( "/busca/?s=" ) . urlencode( get_query_var( 's' ) ) );
        exit();
    }   
}
add_action( 'template_redirect', 'fb_change_search_url_rewrite' );

Add the following to your htaccess file:

RewriteCond %{QUERY_STRING} ^s=(.*)$ [NC]
RewriteRule ^$ /busca/%1 [NC,QSA,L]

Note: Code is untested

Edit: Minor modifications made to answer the question more thoroughly

6
  • But I need the ?s= parameter, I need something like: /busca/?s=my-word Commented Jan 24, 2014 at 3:57
  • Minor modifications to this code should be able to accomplish what you're asking. Just a sec. Commented Jan 24, 2014 at 3:59
  • When I tried I got just 404. Commented Jan 24, 2014 at 4:07
  • Give the new code a try. Commented Jan 24, 2014 at 4:24
  • Sorry, but I still got 404. Commented Jan 24, 2014 at 4:48

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.