title: htaccess - rewrite urls with php and mysql
body: <p>I'm trying to do a rewrite of <code>/example-friendly-url</code> to display the content of <code>/posts.php?id=1</code>.</p>
  
  <p>Both the friendly url value and the id are stored in a mysql table.</p>
  
  <p>Here's what I've written so far but something's not right:</p>
  
  <p>posts.php:</p>
  
  <pre><code>include('/functions.php');
  $post = getPost($_GET['id']);
  $param = getSlug($_GET['param']);
  </code></pre>
  
  <p>functions.php:</p>
  
  <pre><code>function getPost($id) {
      $id = (int) $id;
      $query = mysql_query("SELECT * FROM list WHERE id = '$id'") or die(mysql_error());
      return mysql_fetch_assoc($query);
  }
  
  function getSlug($param) {
      $query = mysql_query("SELECT id FROM list WHERE slug = '$param'") or die(mysql_error());
      return mysql_fetch_assoc($query);
  }
  </code></pre>
  
  <p>.htaccess:</p>
  
  <pre><code>Options +FollowSymlinks
  RewriteEngine On
  RewriteCond %{REQUEST_URI} !^/posts.php
  RewriteCond %{REQUEST_URI} !^/$
  RewriteRule ^/(.*)$ %{DOCUMENT_ROOT}/posts.php?param=$1 [NC,L]
  </code></pre>
  
  <p>Any help would be much appreciated.</p>