Rewrite search url in wordpress

I have tried several different .htaccess solutions as well as plugins, but nothing seems to be working. I have different links that use an url like this on my WordPress site:

http://www.mydomainname.com/?s=&post_type=schools&general_search=1&general_search_term=Science

Read More

How would I rewrite those urls to look like:
http://mydomainname.com/search/science in the browser?

Thanks!

Here is what I have in the .htaccess file:

# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^search/(.+)$ /?s=&post_type=schools&general_search=1&general_search_term=$1 [L,QSA,NC]
</IfModule>
# END WordPress

Related posts

Leave a Reply

3 comments

  1. Simply way

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

    You can use wordpress redirect functions

  2. Try this code in your .htaccess:

    Options +FollowSymLinks -MultiViews
    # Turn mod_rewrite on
    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^search/(.+)$ /?s=&post_type=schools&general_search=1&general_search_term=$1 [L,QSA,NC]
    

    EDIT:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    Options +FollowSymLinks -MultiViews
    RewriteEngine On
    RewriteBase /
    RewriteRule ^search/(.+)$ /?s=&post_type=schools&general_search=1&general_search_term=$1 [L,QSA,NC]
    
    RewriteCond %{ENV:REDIRECT_STATUS} !200
    RewriteRule ^index.php$ - [L]
    
    RewriteCond %{ENV:REDIRECT_STATUS} !200
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress