title: Url rewrite with parameter using .htaccess
body: <p>I have a URL <code>page.php?id=param</code> which is creating dynamically. </p>
  
  <p>In this URL <code>page.php</code> and <code>param</code> are dynamic so my HTML link looks like </p>
  
  <pre><code>&lt;a href="page.php?id=param"&gt;link&lt;/a&gt;
  </code></pre>
  
  <p>I need this URL as </p>
  
  <pre><code>mydomain.com/param
  </code></pre>
  
  <p>and it should go to <code>page.php</code> and the parameter <code>id</code> should be used from <code>page.php</code>.</p>
  
  <p>This is the code I'm using right now </p>
  
  <pre><code># To externally redirect /dir/foo.php?id=123 to /dir/foo/123
  RewriteCond %{THE_REQUEST} ^GET\s([^.]+)\.php\?id=([^&amp;\s]+) [NC]
  RewriteRule ^ %1/%2? [R,L]
  
  # To internally forward /dir/foo/12 to /dir/foo.php?id=12
  
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f  
  RewriteRule ^([^/.]+)/?([^/.]+)?/?([^/.]+)?/?([^/.]+)?$ /$1.php?id=$2 [QSA,L]
  </code></pre>
  
  <p>But the rewrite is as follows:</p>
  
  <pre><code>mydomain.com/page/param
  </code></pre>
  
  <p>The required output should be:</p>
  
  <pre><code>mydomain.com/param
  </code></pre>