How To Make The WordPress Search URL Pretty

Frank from WPEngineer explains how to make pretty URLs for the WordPress search function. Also take a look in the comments on the post as Chuck Reynolds provides a snippet of code you can place in your htaccess file to accomplish the same thing.

Would you like to write for WP Tavern? We are always accepting guest posts from the community and are looking for new contributors. Get in touch with us and let's discuss your ideas.

3 Comments


  1. Here’s a better way:

    RewriteCond %{QUERY_STRING} s=(.*)
    RewriteRule ^$ /search/%1? [R,L]

    That will do more what people are expecting, I think.

    Report


  2. Or with WordPress Rewrite Rules in functions.php :

    function feed_dir_rewrite( $wp_rewrite ) {
        $feed_rules = array( 'search/(.+)' => 'index.php?s=' . $wp_rewrite->preg_index(1));
        $wp_rewrite->rules = $feed_rules + $wp_rewrite->rules;
    }
    add_filter( 'generate_rewrite_rules', 'feed_dir_rewrite' );

    Report


  3. Another quality find – thank you for bringing this to my attention

    Report

Comments are closed.