title: How Apache mod_rewrite Module works?
body: <p>I'm trying to make my own MVC PHP framework using a tutorial that i found over the net .
  but i got a problem understanding the rewrite_mod in the htaccess files. here is the first part : </p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
      RewriteEngine on
      RewriteRule    ^$    public/     [L]
      RewriteRule    (.*) public/$1    [L]
   &lt;/IfModule&gt;
  </code></pre>
  
  <p>1) As written in the tutorial those rules will redirect all the request to the public folder , so the first question is why we have two rules ? what means the first and the second. one
  2) the second part is another htaccess file in the public folder containing :</p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
  RewriteEngine On
  
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  
  RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
  
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>the second part will rewrite the url to index.php?url=$1 this part is clear but this part is little bit difficult for me  </p>
  
  <pre><code>RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  </code></pre>
  
  <p>i learn about it and it tell that the request should not be a file or directory but the index.php is a file (in public directory) .
  anothe question please why when we remove the last .htaccess file (in public directory)  we
  got this error : </p>
  
  <pre><code>Internal Server Error
  
  The server encountered an internal error or misconfiguration and was unable to complete your request.
  
  Please contact the server administrator at admin@127.0.0.1 to inform them of the time this error occurred, and the actions you performed just before this error.
  
  More information about this error may be available in the server error log.
  
  Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
  </code></pre>
  
  <p>and when we have only a htacces containting only this part ,it works great ?</p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
  RewriteEngine On
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>Thanks so much .</p>