I am attempting to transform this URL:

http://localhost/?q=foo&s=search

about this:

http://localhost/?q=+foo&s=search (i add a plus sign before the user query)

I attempted with:

RewriteCond %{QUERY_STRING} ^q=(.*)$ [NC]
RewriteRule ^(.*)$ /?q=\+%1 [R=301,L,NE]

But this creates:

http://localhost/?q=+++++++++++++++++++++foo

Any advice regarding how to add the plus sign prior to the query?

Two quick/easy options:

  1. Add the + within the after sales (PHP: $query = '+' . $_GET['q'];)
  2. Give a param showing the redirect and staying away from the redirect.

    # The example is untested, but the idea is to add an extra 
    # query parameter (rw=1). When the redirect comes back through, 
    # the redirect is not applied, as the '+' as already been 
    # put on the beginning.
    
    RewriteCond %{QUERY_STRING} !&rw=1$ [NC]
    RewriteCond %{QUERY_STRING} ^q=(.*)$ [NC]
    RewriteRule ^(.*)$ /?q=\+%1&rw=1 [R=301,L,NE]