title: Apache rewrite to new page with parameters included
body: <p>I have external sites linking to my page at:</p>
  
  <p><a href="http://www.example.com/old.php?page=55555" rel="nofollow noreferrer">http://www.example.com/old.php?page=55555</a></p>
  
  <p>but now I need them redirected to:</p>
  
  <p><a href="http://www.example.com/new.php?page=55555" rel="nofollow noreferrer">http://www.example.com/new.php?page=55555</a></p>
  
  <p>A have seen redirects solved, but those were different, they were translated to a different kind of url (eg. example.com/page/55555) or other domain, not the same domain and same url construction.</p>
  
  <p>I did get it to work without the parameters using 
  RewriteRule old.php new.php, but this does not work when passing the params.</p>
  
  <p>Just renaming the page is not an option :)
  Thanks !</p>
  
  <p>EDIT:</p>
  
  <p>This is the code that works, but only without the parameters. Whenever you add "?page=55555", it does not work anymore.</p>
  
  <pre><code>RewriteRule old.php new.php [R=302,NC]
  </code></pre>
  
  <p>This is another variation I had tried, but could not get it to work:</p>
  
  <pre><code>RewriteRule ^old\.php?([0-9]*) new.php?page=$1 [NC,QSA]
  </code></pre>
  
  <p>EDIT2:</p>
  
  <p>The answer given works, however it does only when I remove the following 4 lines from the .htaccess file:</p>
  
  <pre><code>RewriteCond %{QUERY_STRING} !marker  
  RewriteCond %{QUERY_STRING} page=([0-9]+)
  RewriteRule ^/?new.php$ %1? [R=301,L]
  RewriteRule ^/?p([-a-zA-Z0-9_+]+)$ new.php?marker&amp;page=$1 [L]
  </code></pre>
  
  <p>These 4 lines make it possible to enter 
  <a href="http://www.example.com/p4444" rel="nofollow noreferrer">http://www.example.com/p4444</a> 
  in the browser, and it will open 
  <a href="http://www.example.com/new.php?page=4444" rel="nofollow noreferrer">http://www.example.com/new.php?page=4444</a> 
  (but still mask it with <a href="http://www.example.com/p4444" rel="nofollow noreferrer">http://www.example.com/p4444</a>)</p>
  
  <p>I would like both old.php and new.php to work this way. I hope this is clear.</p>