Add GET based search arguments to url with mod_rewrite
<p>I am working on a cms that uses mod_rewrite to provide provide pretty URLs. The basic use case just takes any path and rewrites it to individual GET arguments, like this:</p>

<pre><code>RewriteRule ^([\w-]+)[/]?$ index.php?p1=$1 [L]
RewriteRule ^([\w-]+)/([\w-]+)[/]?$ index.php?p1=$1&amp;p2=$2 [L]
RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)[/]?$ index.php?p1=$1&amp;p2=$2&amp;p3=$3 [L]
RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)/([\w-]+)[/]?$ index.php?p1=$1&amp;p2=$2&amp;p3=$3&amp;p4=$4 [L]
RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)/([\w-]+)/([\w-]+)[/]?$ index.php?p1=$1&amp;p2=$2&amp;p3=$3&amp;p4=$4&amp;p5=$5 [L]
</code></pre>

<p>I also have a search form that sends GET requests, but I am not sure how to add this to the rewrite rules. For example:</p>

<p><a href="http://site.domain/search?query=abc" rel="nofollow">http://site.domain/search?query=abc</a></p>

<p>should rewrite to:</p>

<p><a href="http://site.domain/index.php?p1=search&amp;query=abc" rel="nofollow">http://site.domain/index.php?p1=search&amp;query=abc</a></p>

<p>I have attempted the following, with some variations, but the search arguments do not appear in $_GET as expexted:</p>

<pre><code>RewriteRule ^search?(.+)[/]?$ index.php?p1=search$1[L]
</code></pre>