title: Rewrite URLs in RESTful API
body: <p>I have to create an API in PHP, which I have never done before. I have a index.php in my root folder which contains a form. A button click activates an AJAX Request to read all entries and a form can be filled out to send data. I will also have DELETE and update.</p>
  
  <p><strong>ajaxcall.js</strong></p>
  
  <pre><code> // GET to retrieve
   var req;
     req=new XMLHttpRequest();
     req.open("GET", 'src/api/v1/posts',true);
     req.send();
  
    //post with ajax
      $.ajax({
          type:"POST",
          url: "src/api/v1/posts",
          data: test,
          ContentType:"application/json",
  
          success:function(){
              alert('successfully posted');
          },
          error:function(){
              alert('Could not be posted');
          }
  
      });
  </code></pre>
  
  <p>I have a folder src/api/v1 in there I want the endpoint file api.php which handles the different requests. I now need all the AJAX calls to be resend to api.php which sits inside that v1 folder. I created an .htaccess which is stored in also stored in src/api/v1. I added the following:</p>
  
  <p><strong>.htaccess</strong></p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
  Options +FollowSymLinks
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule src/api/v1/(.*)$ src/api/v1/api.php?request=$1 [QSA,NC,L]
  </code></pre>
  
  <p> </p>
  
  <p>Unfortunately I get a 404 not found, it just does not seem to re-write the URL to the api.php so it is looking for /posts which does not exists. What am I doing wrong? </p>