title: mod_rewrite with question marks and ampersands (with PHP)
body: <p>I have a PHP-based web app that I'm trying to apply Apache's mod_rewrite to.</p>
  
  <p>Original URLs are of the form:<br>
    <a href="http://example.com/index.php?page=home&amp;x=5" rel="nofollow noreferrer">http://example.com/index.php?page=home&amp;x=5</a></p>
  
  <p>And I'd like to transform these into:<br>
    <a href="http://example.com/home?x=5" rel="nofollow noreferrer">http://example.com/home?x=5</a></p>
  
  <p>Note that while rewriting the page name, I'm also effectively "moving" the question mark.  When I try to do this, Apache happily performs this translation:</p>
  
  <pre><code>RewriteRule ^/([a-z]+)\?(.+)$ /index.php?page=$1&amp;$2  [NC,L]
  </code></pre>
  
  <p>But it messes up the <code>$_GET</code> variables in PHP.  For example, a call to <code>http://example.com/home?x=88</code> yields only one <code>$_GET</code> variable (<code>page =&gt; home</code>).  Where did <code>x =&gt; 88</code> go?  However, when I change my rule to use an ampersand rather than a question mark:</p>
  
  <pre><code>RewriteRule ^/([a-z]+)&amp;(.+)$ /index.php?page=$1&amp;$2  [NC,L]
  </code></pre>
  
  <p>a call like <code>http://example.com/home&amp;x=88</code> will work just as I'd expect it to (i.e. both the <code>page</code> and <code>x</code> $_GET variables are set appropriately).</p>
  
  <p>The difference is minimal I know, but I'd like my URL variables to "start" with a question mark, if it's possible.  I'm sure this reflects my own misunderstanding of how mod_rewrite redirects interact with PHP, but  it seems like I should be able to do this (one way or another).</p>
  
  <p>Thanks in advance!<br>
  Cheers,<br>
  -Chris</p>