title: PHP .htaccess -> pretty url (in reverse)
body: <p>I know how to make URL's rewrite, for example: 
  <code>www.example.com/index.php?id=1&amp;cat=3</code> to <code>www.example.com/1/3/</code> (or whatever). I know that.</p>
  
  <p>What I don't know is how on earth to change my whole links in all pages to link to pretty URL's. All my site's links are old fashion (<code>&lt;a href="index.php?id=1&amp;cat=2"&gt;</code>) and there are many.</p>
  
  <p>I`m asking if someone has an idea or know how to automaticaly redirect to that pretty url if the user click on index.php?id=1. (Almost like this site Stackoverflow if you change title in the url).</p>
  
  <p>So my presumtions are...</p>
  
  <ol>
  <li><p>Use .htaccess to read the index.php?id=1&amp;cat=2 to rewrite index/1/3 that itself interprets again (strange)</p></li>
  <li><p>a php file to do the redirects that htaccess rewrites back to original... </p></li>
  </ol>
  
  <p>Conclusion: change <code>&lt;a href="index.php?id=1&amp;....."&gt;</code> automaticaly to <code>index/1/2</code></p>
  
  <hr>
  
  <h2>SOLVED</h2>
  
  <pre><code>Options +FollowSymLinks
  RewriteEngine On
  RewriteBase /
  
  ##################################
  # This turns index.php?id=1&amp;cat=2 into index/1/2 and then back 'transparent' into    index.php?id=1&amp;cat=2 if you have old fashioned
  # links in your site and don't want to change them :)
  
  
  # Avoid mod_rewrite infinite loops 
  # This is critical if you want to use this code
  
  RewriteCond %{ENV:REDIRECT_STATUS} 200
  RewriteRule .* - [L]
  
  # Hard-rewrite ("[R]") to "friendly" URL.
  # Needs RewriteCond to match original querystring.
  # Uses "?" in target to remove original querystring,
  #   and "%n" backrefs to move its components.
  # Target must be a full path as it's a hard-rewrite.
  RewriteCond %{QUERY_STRING} ^id=(\d+)&amp;cat=(\d+)$
  RewriteRule ^index.php$ http://localhost/index/%1/%2/? [L,R]
  
  # Soft-rewrite from "friendly" URL to "real" URL.
  # Transparent to browser.
  # Won't re-trigger the above rewrite, though I'm
  #   not really sure why! The order of the rules
  #   doesn't seem to make a difference.
  RewriteRule ^index/(\d+)/(\d+)/$ index.php?id=$1&amp;cat=$2 [L]
  </code></pre>