title: REST php Rewrite Rules
body: <p>I try to make a rest-api to Post / Put / Get and Delete Guitars.</p>
  
  <p>Now i already can use POST / GET and DELETE .. and i kinda gonna wrestle with PUT the next few days.</p>
  
  <p>Now i have allready rewritten my .htacces to get an format as XML or JSON if i put .json or .xml behind my URI.</p>
  
  <p>In my JSON i have putten a self-link type and the href is the link with the id attached to it.</p>
  
  <p>For some reason if i click on the links i just keep getting the Summary Page with ALL ID's. I don't know what i am doing wrong :S</p>
  
  <p>.htacces file</p>
  
  <pre><code>    RewriteEngine on
  #Get Whole Guitar Summary
  RewriteRule ^guitars$ service.php?type=json [QSA]
  RewriteRule ^guitars.json$ service.php?type=json [QSA]
  RewriteRule ^guitars.xml$ service.php?type=xml [QSA]
  
  
  #Only Get Guitar by ID
  RewriteRule ^guitars/([0-9]*)$ service.php?id=$1&amp;type=json 
  RewriteRule ^guitars/([0-9]*).json$ service.php?id=$1&amp;type=json 
  RewriteRule ^guitars/([0-9]*).xml$ service.php?id=$1&amp;type=xml 
  </code></pre>
  
  <p>This is my "GET" case in my Service.php</p>
  
  <pre><code>case "GET":
   //GET METHODE
   $guitars = 'SELECT * FROM gitaren';
   $GuitarSummary = mysqli_query($dbconnect, $guitars);
  
  
  //Representaties instellen
  if($_GET['type'] == 'json'){
      header('Content-Type: application/json');
      while($row= mysqli_fetch_assoc($GuitarSummary)){
          $jsonArray[] = array(
              "id" =&gt; $row['id'],
              "brand" =&gt; $row['brand'],
              "model" =&gt; $row['model'],
              "strings" =&gt; $row['strings'],
              "price" =&gt; $row['price'],
              "available" =&gt; $row['available'],
              "link" =&gt; array(
                  'rel' =&gt; 'self',
                  'href' =&gt; 'http://localhost/imp6-webservices/eindopdracht/gitaren/'.$row['id']
              )
          );
      }
          echo json_encode($jsonArray);
  }
  else {
  header ('Content-Type: text/xml');
      echo "&lt;?xml version='1.0' encoding ='UTF-8'?&gt;";
      echo "&lt;gitaren&gt;";
      while($row= mysqli_fetch_assoc($GuitarSummary)){
          echo "&lt;gitaar&gt;";
          echo "&lt;id&gt;".$row['id']."&lt;/id&gt;";
          echo "&lt;brand&gt;".$row['brand']."&lt;/brand&gt;";
          echo "&lt;model&gt;".$row['model']."&lt;/model&gt;";
          echo "&lt;strings&gt;".$row['strings']."&lt;/strings&gt;";
          echo "&lt;price&gt;".$row['price']."&lt;/price&gt;";
          echo "&lt;available&gt;".$row['available']."&lt;/available&gt;";
          echo "&lt;/gitaar&gt;";
      }
      echo "&lt;/gitaren&gt;";
  }
  
  
  //Zoekqueries voor POSTman overzicht
  if(isset($_GET['brand']))
  {
      $brand =  $_GET['brand'];
      $query = "SELECT * FROM gitaren WHERE brand = '$brand'  ";
  }
      if (isset($_GET['model']))
      {
          $model = $_GET['model'];
          $query = "SELECT * FROM gitaren WHERE model = '$model'  ";
      }
      if (isset($_GET['strings']))
      {
          $strings = $_GET['strings'];
          $query = "SELECT * FROM gitaren WHERE strings = '$strings'  ";
      }
      if (isset($_GET['price']))
      {
          $price = $_GET['price'];
          $query = "SELECT * FROM gitaren WHERE price = '$price'  ";
      }
      if (isset($_GET['available']))
      {
          $available = $_GET['available'];
          $query = "SELECT * FROM gitaren WHERE available = '$available'  ";
      }
      break;
  </code></pre>
  
  <p>Please dont mind the Dutch commentary putted in and the XML colomns in Dutch.</p>
  
  <p>I hope you guys can help me out.</p>
  
  <p>Kind Regards,</p>
  
  <p>Jay!</p>