title: mod_rewrite's RewriteMap prg works just for first request
body: <p>I'm creating a simple IP blacklist. Each request is evaluated against list of IPs and throws 403 if necessary. I decided to deal with it on Apache side with <code>mod_rewrite</code>, its <code>RewriteMap</code> and simple python script.</p>
  
  <p>In <code>VirtualHost</code>:</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
      ...
  
      RewriteEngine On
  
      RewriteMap banip prg:/path/to/script.py
      RewriteCond ${banip:%{REMOTE_ADDR}} !=OK
      RewriteRule ^/.* - [F]
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p><strong>script.py:</strong></p>
  
  <pre><code>#!/usr/bin/python
  import sys
  
  sys.stdout.write('OK\n')
  sys.stdout.flush()
  </code></pre>
  
  <p>Now the weird part. After restart of Apache, only first request returns <code>200</code> and every following request returns <code>403</code>. I'd expect all of them to return <code>200</code>. When I restart Apache, the same happens all over again.</p>
  
  <p><strong>Rewrite log after restart of Apache:</strong></p>
  
  <pre><code># Very first request
  127.0.0.1 - (2) init rewrite engine with requested uri /app_dev.php/
  127.0.0.1 - (3) applying pattern '^/.*' to uri '/app_dev.php/'
  127.0.0.1 - (5) map lookup OK: map=banip key=127.0.0.1 -&gt; val=OK
  127.0.0.1 - (4) RewriteCond: input='OK' pattern='!=OK' =&gt; not-matched
  127.0.0.1 - (1) pass through /app_dev.php/
  
  ...
  
  # Request after that
  127.0.0.1 - (2) init rewrite engine with requested uri /static/css/grid.css
  127.0.0.1 - (3) applying pattern '^/.*' to uri '/static/css/grid.css'
  127.0.0.1 - (5) map lookup OK: map=banip key=127.0.0.1 -&gt; val=
  127.0.0.1 - (4) RewriteCond: input='' pattern='!=OK' =&gt; matched
  127.0.0.1 - (2) forcing responsecode 403 for /static/css/grid.css
  </code></pre>
  
  <p>On second refresh, it doesn't write <em>anything</em> to rewrite log, just throws <code>403</code> straight away.</p>
  
  <p>When I try <code>RewriteCond OK !=OK</code> or <code>RewriteCond NOTOK !=OK</code>, it works perfect. Any idea why is this happening?</p>
  
  <p>I'm on Xubuntu 11.10 with Apache 2.2.20 and Python 2.7.2.</p>