I would recommend redirecting from index.php rather than use of rewrite rules in this case.
Rewrite rules also have cost, and they will be checked on every page load
In the beginning of index.php:
<?php
if(!empty($_GET["search"]))
{
header("Location: search?q=".rawurlencode($_GET["search"]));
exit;
}
?>
As Olaf Dietsche rightfully noted in the comments, mod_rewrite outperforms PHP, so the question is really what is the hit ratio of index.php vs other files. If it is low, php approach is definitely better, however, if index.php hits 50% of the time or so, then you might be better off with rewriting.
Hence, adding mod_rewrite solution as well:
RewriteEngine on
RewriteCond %{QUERY_STRING} (?:^|&)search=([^&]+)
RewriteRule ^index.php$ /search?q=%1 [R,L]
RewriteCond actually looks for search= query string parameter and ensures it's not empty
And the rule simply rewrites anything from index.php into /search?q=<query>
Note that %1 used to match the first captured sub-pattern matched from the conditions (rather than from the matching part of the rule itself - in which case we would need to use $1).
However, the real question is why we are dealing with this problem in first place.
If search is done by submitting a value in a page, then it's form submission and as such it can be pointed directly to the handler and not redirected there afterwards. This is much more efficient.
<form action="/search" method="get">
<input type="text" name="q">
...
This way, anything submitted from the search form will go directly to /search and will not need a redirect to deal with.
http://mySite.com/?q=query..