title: Difference in .htaccess behaviour
body: <p>I have finished developing a micro app with Phalcon and tried to move it to production server, but have encountered some problems with <code>.htaccess</code> rules.</p>
  
  <p>Directory layout on the serwer is like this : </p>
  
  <pre><code>/var/www
  |- .htaccess
  |- redmine/
  |- wordpress/
  |- (other dirs)
  |- MyApp/
     |- .htaccess
     |- public/
        |- .htaccess
        |- api.php
  </code></pre>
  
  <p>/var/www/.htaccess : </p>
  
  <pre><code># BEGIN WordPress
  &lt;IfModule mod_rewrite.c&gt;
      RewriteEngine On
      RewriteBase /
      RewriteRule ^index\.php$ - [L]
      RewriteCond %{REQUEST_URI} !(redmine|MyApp) [NC]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.php [L]
  &lt;/IfModule&gt;
  
  # END WordPress
  </code></pre>
  
  <p>/var/www/MyApp/.htaccess :</p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
      RewriteEngine On
      RewriteCond %{REQUEST_URI} !(\.gif|\.jpg|\.png|\.mp3|\.ods|\.csv|\.xls)$ [NC]
      RewriteRule  ^$ public/    [L]
      RewriteCond %{REQUEST_URI} !(\.gif|\.jpg|\.png|\.mp3|\.ods|\.csv|\.xls)$ [NC]
      RewriteRule  (.*) public/$1 [L]
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>/var/www/MyApp/public/.htaccess :</p>
  
  <pre><code>&lt;IfModule mod_rewrite.c&gt;
     RewriteEngine On
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteRule ^(.*)$ api.php?_url=/$1 [QSA,L]
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>I'm really new to all this. The top-most <code>.htaccess</code> was not setup by me, and frankly I don't know what is going on in there. The others are based on Phalcon tutorials.</p>
  
  <p>Everything worked on my local machine, but stopped when I uploaded it. I turned on logging in both places.</p>
  
  <p>Local log :</p>
  
  <pre><code>[perdir /Users/Losiowaty/MyApp/] add path info postfix: /Users/Losiowaty/MyApp/api -&gt; /Users/Losiowaty/MyApp/api/poeci
  [perdir /Users/Losiowaty/MyApp/] strip per-dir prefix: /Users/Losiowaty/MyApp/api/poeci -&gt; api/poeci
  [perdir /Users/Losiowaty/MyApp/] applying pattern '^$' to uri 'api/poeci'
  [perdir /Users/Losiowaty/MyApp/] add path info postfix: /Users/Losiowaty/MyApp/api -&gt; /Users/Losiowaty/MyApp/api/poeci
  [perdir /Users/Losiowaty/MyApp/] strip per-dir prefix: /Users/Losiowaty/MyApp/api/poeci -&gt; api/poeci
  [perdir /Users/Losiowaty/MyApp/] applying pattern '(.*)' to uri 'api/poeci'
  [perdir /Users/Losiowaty/MyApp/] RewriteCond: input='/MyApp/api/poeci' pattern='!(\\.gif|\\.jpg|\\.png|\\.mp3|\\.ods|\\.csv|\\.xls)$' [NC] =&gt; matched
  [perdir /Users/Losiowaty/MyApp/] rewrite 'api/poeci' -&gt; 'public/api/poeci'
  [perdir /Users/Losiowaty/MyApp/] add per-dir prefix: public/api/poeci -&gt; /Users/Losiowaty/MyApp/public/api/poeci
  [perdir /Users/Losiowaty/MyApp/] strip document_root prefix: /Users/Losiowaty/MyApp/public/api/poeci -&gt; /MyApp/public/api/poeci
  [perdir /Users/Losiowaty/MyApp/] internal redirect with /MyApp/public/api/poeci [INTERNAL REDIRECT]
  [perdir /Users/Losiowaty/MyApp/public/] add path info postfix: /Users/Losiowaty/MyApp/public/api -&gt; /Users/Losiowaty/MyApp/public/api/poeci
  [perdir /Users/Losiowaty/MyApp/public/] strip per-dir prefix: /Users/Losiowaty/MyApp/public/api/poeci -&gt; api/poeci
  [perdir /Users/Losiowaty/MyApp/public/] applying pattern '^(.*)$' to uri 'api/poeci'
  [perdir /Users/Losiowaty/MyApp/public/] RewriteCond: input='/Users/Losiowaty/MyApp/public/api' pattern='!-d' =&gt; matched
  [perdir /Users/Losiowaty/MyApp/public/] RewriteCond: input='/Users/Losiowaty/MyApp/public/api' pattern='!-f' =&gt; matched
  [perdir /Users/Losiowaty/MyApp/public/] rewrite 'api/poeci' -&gt; 'api.php?_url=/api/poeci'
  split uri=api.php?_url=/api/poeci -&gt; uri=api.php, args=_url=/api/poeci
  [perdir /Users/Losiowaty/MyApp/public/] add per-dir prefix: api.php -&gt; /Users/Losiowaty/MyApp/public/api.php
  [perdir /Users/Losiowaty/MyApp/public/] strip document_root prefix: /Users/Losiowaty/MyApp/public/api.php -&gt; /MyApp/public/api.php
  [perdir /Users/Losiowaty/MyApp/public/] internal redirect with /MyApp/public/api.php [INTERNAL REDIRECT]
  [perdir /Users/Losiowaty/MyApp/public/] strip per-dir prefix: /Users/Losiowaty/MyApp/public/api.php -&gt; api.php
  [perdir /Users/Losiowaty/MyApp/public/] applying pattern '^(.*)$' to uri 'api.php'
  [perdir /Users/Losiowaty/MyApp/public/] RewriteCond: input='/Users/Losiowaty/MyApp/public/api.php' pattern='!-d' =&gt; matched
  [perdir /Users/Losiowaty/MyApp/public/] RewriteCond: input='/Users/Losiowaty/MyApp/public/api.php' pattern='!-f' =&gt; not-matched
  [perdir /Users/Losiowaty/MyApp/public/] pass through /Users/Losiowaty/MyApp/public/api.php
  </code></pre>
  
  <p>Remote log :</p>
  
  <pre><code>[perdir /var/www/MyApp/] add path info postfix: /var/www/MyApp/api -&gt; /var/www/MyApp/api/poeci
  [perdir /var/www/MyApp/] strip per-dir prefix: /var/www/MyApp/api/poeci -&gt; api/poeci
  [perdir /var/www/MyApp/] applying pattern '^$' to uri 'api/poeci'
  [perdir /var/www/MyApp/] add path info postfix: /var/www/MyApp/api -&gt; /var/www/MyApp/api/poeci
  [perdir /var/www/MyApp/] strip per-dir prefix: /var/www/MyApp/api/poeci -&gt; api/poeci
  [perdir /var/www/MyApp/] applying pattern '(.*)' to uri 'api/poeci'
  [perdir /var/www/MyApp/] RewriteCond: input='/MyApp/api/poeci' pattern='!(\\.gif|\\.jpg|\\.png|\\.mp3|\\.ods|\\.csv|\\.xls)$' [NC] =&gt; matched
  [perdir /var/www/MyApp/] rewrite 'api/poeci' -&gt; 'public/api/poeci'
  [perdir /var/www/MyApp/] add per-dir prefix: public/api/poeci -&gt; /var/www/MyApp/public/api/poeci
  [perdir /var/www/MyApp/] strip document_root prefix: /var/www/MyApp/public/api/poeci -&gt; /MyApp/public/api/poeci
  [perdir /var/www/MyApp/] internal redirect with /MyApp/public/api/poeci [INTERNAL REDIRECT]
  [perdir /var/www/MyApp/public/] add path info postfix: /var/www/MyApp/public/api.php -&gt; /var/www/MyApp/public/api.php/poeci
  [perdir /var/www/MyApp/public/] strip per-dir prefix: /var/www/MyApp/public/api.php/poeci -&gt; api.php/poeci
  [perdir /var/www/MyApp/public/] applying pattern '^(.*)$' to uri 'api.php/poeci'
  [perdir /var/www/MyApp/public/] RewriteCond: input='/var/www/MyApp/public/api.php' pattern='!-d' =&gt; matched
  [perdir /var/www/MyApp/public/] RewriteCond: input='/var/www/MyApp/public/api.php' pattern='!-f' =&gt; not-matched
  [perdir /var/www/MyApp/public/] pass through /var/www/MyApp/public/api.php
  [perdir /var/www/MyApp/public/] add path info postfix: /var/www/MyApp/public/api.php -&gt; /var/www/MyApp/public/api.php/poeci
  [perdir /var/www/MyApp/public/] strip per-dir prefix: /var/www/MyApp/public/api.php/poeci -&gt; api.php/poeci
  [perdir /var/www/MyApp/public/] applying pattern '^(.*)$' to uri 'api.php/poeci'
  [perdir /var/www/MyApp/public/] RewriteCond: input='/var/www/MyApp/public/api.php' pattern='!-d' =&gt; matched
  [perdir /var/www/MyApp/public/] RewriteCond: input='/var/www/MyApp/public/api.php' pattern='!-f' =&gt; not-matched
  [perdir /var/www/MyApp/public/] pass through /var/www/MyApp/public/api.php
  [perdir /var/www/] strip per-dir prefix: /var/www/poeci -&gt; poeci
  [perdir /var/www/] applying pattern '^index\\.php$' to uri 'poeci'
  [perdir /var/www/] strip per-dir prefix: /var/www/poeci -&gt; poeci
  [perdir /var/www/] applying pattern '.' to uri 'poeci'
  [perdir /var/www/] RewriteCond: input='/poeci' pattern='!(redmine|MyApp)' [NC] =&gt; matched
  [perdir /var/www/] RewriteCond: input='/var/www/poeci' pattern='!-f' =&gt; matched
  [perdir /var/www/] RewriteCond: input='/var/www/poeci' pattern='!-d' =&gt; matched
  [perdir /var/www/] rewrite 'poeci' -&gt; '/index.php'
  [perdir /var/www/] trying to replace prefix /var/www/ with /
  [perdir /var/www/] internal redirect with /index.php [INTERNAL REDIRECT]
  </code></pre>
  
  <p>The differences begin with the first line with <code>[perdir (...)]</code> ending with <code>/public/</code>. I don't understand why it adds <code>.php</code> and why the <code>!-f</code> rule doesn't match on the remote server.</p>
  
  <p>Local server :<br>
  OSX 10.9.3, MAMP 3.0.4, Apache 2.2.26</p>
  
  <p>Remote server :<br>
  Debian GNU/Linux 6.0.9, Apache 2.2.16</p>
  
  <p>I wonder whether this is caused by the additional <code>.htaccess</code> file on the remote, or by the difference in Apache version.</p>
  
  <p>I'd appreciate some explanation as to what's going on and any directions on where to look for answers.</p>
  
  <p>Cheers!</p>