• Resolved articlepedia

    (@articlepedia)


    Hi All,

    I am trying to make the searching url friendly for search engines. I want to modify the search url by search_rewrite_rules filter, it works on my local computer but unfortunately it does not work on my production website. The code is below:

    function custom_search_url( $search_rewrite ) {
    if( !is_array( $search_rewrite ) ) {
    return $search_rewrite;
    }
    $new_array = array();
    foreach( $search_rewrite as $pattern => $s_query_string ) {
    $new_array[ str_replace( ‘search/’, ‘searchkeyword/’, $pattern ) ] = $s_query_string;
    }
    $search_rewrite = $new_array;
    unset( $new_array );
    return $search_rewrite;
    }
    add_filter(“search_rewrite_rules”, “custom_search_url”);

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    It’s maybe due to different PHP versions. I don’t see anything obvious that would cause a difference between versions. Perhaps it is in how $pattern => is handled? You don’t really need this, I suggest removing it and use $s_query_string alone consistently.

    Thread Starter articlepedia

    (@articlepedia)

    Hi @bcworkz,

    Thanks for your response.
    It is solved now. The solution is just to open and save the permanent url ( i.e pretty url ) after applying the above filter.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘search_rewrite_rules filter does not work’ is closed to new replies.