title: Apache Rewrite module, complex rules
body: <p>I basically want to redirect all requests to index.php doesn't matter what, except those with certain <code>REQUEST_URI</code>. Those requests that look like image files, so have an ending like: <code>.jpg</code> or <code>.png</code> should be examined and if they are under the <code>public/</code> folder (or any subfolders in any depth) and if they are they should be served and the rewriting process should stop here! If not, I want to redirect to a default image at <code>public/errors/image-not-found.png</code> and terminate rewriting process. The other exceptions are files that end with <code>.js, .css, .html</code> or <code>.swf</code>. They also should only be served if they are located under the <code>public/</code> folder or any other subfolders. If not, a simple <code>404-Not found</code> should be sent back. In either case of the last to the rewriting process need to stop of course.
  Any other request should be redirected to <code>index.php</code> and appended as a <code>query string</code>. (even if the request points to a directory or to a file that is not under the conditions aforesaid, but exists, e.g: <code>www.xyz.com/library/Database.php</code> -> <code>www.xyz.com/index.php?url=library/Database.php</code>)</p>
  
  <p>I have half-measure solution:<br/>This is how I redirect everything to index.php: </p>
  
  <pre><code>RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
  </code></pre>
  
  <p>I append a visual explanation of what I want. Maybe this is clearer: <a href="https://i.stack.imgur.com/HvvEE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HvvEE.jpg" alt="flowchart"></a></p>