title: Show one folder up's file if file is not found in current folder htaccess
body: <p>I want to write a simple <strong><code>.htaccess</code></strong> script to do the following task:</p>
  
  <ul>
  <li>there is a folder with documents in <code>http://www.website.com/files/documents/</code></li>
  <li>this folder contains some <code>subfolders</code> called such as <code>images</code>, <code>sheets</code>, <code>texts</code> etc.</li>
  <li>there can be some documents both in the <code>main folder</code> and <code>subfolders</code></li>
  </ul>
  
  <p><strong>The following must happen:</strong></p>
  
  <ul>
  <li><p>User requests <code>http://www.website.com/files/documents/images/image1.jpg</code> and the file does not exist --> user is redirected one directory up to <code>http://www.website.com/files/documents/image1.jpg</code> where the file exists</p></li>
  <li><p>User requests <code>http://www.website.com/files/documents/sheets/excel.xls</code> and the file does not exist --> user is redirected one directory up to <code>http://www.website.com/files/documents/excel.xls</code> </p></li>
  </ul>
  
  <blockquote>
    <p><strong>Note:</strong> It should be valid for all folder names and independent of number of path</p>
  </blockquote>
  
  <p><strong>Example:</strong> </p>
  
  <p><code>www.example.com/one/two/three/four/3.jpg</code> </p>
  
  <p><code>www.example.com/one/two/three/2.jpg</code> </p>
  
  <p><code>www.example.com/one/two/three/four/five/4.jpg</code></p>
  
  <p><strong>Here's the code that i tried:</strong></p>
  
  <pre><code>RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*?/)?[^/]+/(.+)$ $1$2 [L]
  </code></pre>
  
  <p>It worked for 2 level folder but didn't work for 3 level or more folder.</p>
  
  <p><code>www.example.com/one/two/1.jpg</code> => <strong>worked</strong></p>
  
  <p><code>www.example.com/one/two/three/2.jpg</code> => <strong>didn't worked</strong></p>
  
  <p><code>www.example.com/one/two/three/four/3.jpg</code> => <strong>didn't worked</strong> and so on...</p>