title: How do I preserve the existing query string in a mod_rewrite rule
body: <p>I'm trying to rewrite an url from:</p>
  
  <p><a href="http://domain.com/aa/whatever/whatever.php" rel="nofollow noreferrer">http://domain.com/aa/whatever/whatever.php</a><br>
  to<br>
  <a href="http://domain.com/whatever/whatever.php?language=aa" rel="nofollow noreferrer">http://domain.com/whatever/whatever.php?language=aa</a><br></p>
  
  <p>However, depending on existing $_GET variables, it either has to be ?language or &amp;language.</p>
  
  <p>To do this, I use 2 regexes with the [L] flag:</p>
  
  <pre><code>RewriteRule ^([a-z]{2})/(.*\.php\?.*) /$2&amp;language=$1 [L]
  RewriteRule ^([a-z]{2})/(.*) /$2?language=$1 [L]
  </code></pre>
  
  <p>The second one works as expected... The first one however is never hit (it falls through to the second regex, which does hit), even though Regex Coach does show me that it should.</p>
  
  <p>edit:</p>
  
  <p>If just read that I need to use two backslashes to escape the question mark. If I do this, it does hit on the first regex but never find the other GET variables.</p>