I recently changed my CMS, and want to rewrite some of my URLs to match the new URL/query string parameter format.
The old URL was:
http://www.mysite
Here is another version to get specifically what the OP meant. @smhmic's answer is close to this. I just prefer explicit beginning-or-ampersand to find the parameter, rather than the word-boundary approach. (The accepted answer is overly complicated, and has some issues.)
RewriteCond %{QUERY_STRING} (?:^|&)tag=([^&]*)
RewriteRule ^search\.cgi$ /?s=%1 [NC,R=302]
This is saying:
(?: )
don't capture this as a % number
^|&
at beginning of querystring or after an ampersand (this acts like the word boundary, but specifically for urls).
tag=
the param we're looking for.
( )
capture this, into %1.
[^&]*
zero or more characters not an ampersand (and stopping at ampersand or running to the end).