0

How do I change the search url? I already have something like: /search/keyword But I want to change /search to something else.

How can I do it?

Thank you!

  • What has been your research so far? Sharing your research helps everyone. Tell us what you found and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and above all, it helps you get a more specific and relevant answer. More info about how to ask a good question can be found on the How to Ask page. – kaiser Dec 17 '13 at 15:45
  • yes, I did search in google and wordpress stackexchange but haven't found a solution that did work ok, and some of the solutions were a bit old. So I put here the question to see if there are any better and updated solutions. – dbeja Dec 18 '13 at 12:03
1

Ok, the solution I'm now using is to create a rewrite rule in .htaccess (on the root of wp project) like this:

RewriteCond %{QUERY_STRING} ^s=([^\&]*)$
RewriteRule ^(.*)$ /pesquisar/%1 [NE,L,R=301]

I don't know if it's the best solution but seems to be working ok!

|improve this answer|||||
0

Add this to your functions.php in your theme folder:

function change_search_url_rewrite() {
    if ( is_search() && ! empty( $_GET['s'] ) ) {
        wp_redirect( home_url( "/somethingelse/" ) . urlencode( get_query_var( 's' ) ) );
        exit();
    }   
}
add_action( 'template_redirect', 'change_search_url_rewrite' );
|improve this answer|||||
  • 1
    Wouldn't WP_Rewrite do that as well without an extra redirect? – kaiser Dec 17 '13 at 15:44
  • Probably. This is just one possible solution; it might not be the best. Unfortunately I am not very familiar with WP_Rewrite and I am also struggling with it. – luke Dec 17 '13 at 19:49

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.