title: Htaccess Rewrite Rules for MVC
body: <p>I'm having on hell of a time trying to figure out rewrite rules for my MVC microframework. I'm following the pattern <strong>url.com/:controller/:action/:params</strong> but when assets are requested (such as css, js, or png), I don't want those to be rewritten. Here is my basic folder structure:</p>
  
  <pre><code>index.php
  app/
  --&gt; Config
  --&gt; Controllers
  --&gt; Layout
  --&gt; Lib
  --&gt; Models
  --&gt; Views
  assets/
  --&gt; app/
      --&gt; ...
  --&gt; vendor/
      --&gt; ...
  </code></pre>
  
  <p>So if a request matches the URL pattern I described above, I want it to route to the index.php file. If it matches something in the assets folder, I want it to allow it to go through unaffected.</p>
  
  <p>This is the current .htaccess I've created and have been altering things back and forth:</p>
  
  <pre><code>RewriteEngine On
  RewriteBase /
  
  RewriteCond %{SCRIPT_FILENAME} !-d
  RewriteCond %{SCRIPT_FILENAME} !-f 
  RewriteCond %{REQUEST_URI} !\.(jpg|png|js|css)$
  
  RewriteRule ^([^/]+)(/)([^/]+)(/)(.*) index.php?controller=$1&amp;action=$3&amp;params=$5 [L]
  RewriteRule ^([^/]+)(/)(.*) index.php?controller=$1&amp;action=$3&amp;params= [L]
  RewriteRule ^([^/]+)(/) index.php?controller=$1&amp;action=index&amp;params= [L]
  RewriteRule ^([^/]+) index.php?controller=$1&amp;action=index&amp;params= [L]
  </code></pre>
  
  <p>The url pattern matches fine, but for some reason any requests to the assets folder also get rewritten. Doing some various tests, I've found that the <strong>L</strong> flag, which as I understand it means "last", doesn't stop it from processing further rewrites.</p>
  
  <p>I know other people had to have dealt with this issue before as MVC is such a common pattern. Can anybody point out what I am doing wrong?</p>