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.

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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