title: Python+Flask+Cgi+Apache Rewrite?
body: <p>I have a problem similar to <a href="https://stackoverflow.com/q/9982120/344286">this question</a> - I'm restricted to using 1and1 hosting, running cgi through virtualenv. </p>
  
  <p>I have the following in my <code>.htaccess</code> file:</p>
  
  <pre><code>Options +ExecCGI
  
  DirectoryIndex index.cgi
  
  RewriteEngine On
  RewriteRule ^/mypath/test/index.cgi/(.*)$ - [S=1]
  RewriteRule ^/mypath/test/(.*)$ /mypath/test/index.cgi/$1 [QSA,L]
  </code></pre>
  
  <p>My <code>index.cgi</code> contains </p>
  
  <pre><code>#!/path/to/myenv/bin/python
  
  from wsgiref.handlers import CGIHandler
  from flask import Flask
  
  app = Flask(__name__)
  
  @app.route("/", defaults={"path":''})
  @app.route("/&lt;path:path&gt;")
  def main(path):
      return "oh hai, mr. %s" % path
  
  
  @app.route("/fnord")
  def fnord():
      return "allo"
  
  CGIHandler().run(app)
  </code></pre>
  
  <p>What I would like to be able to do is go to <code>www.mysite.com/mypath/test/page-one</code> and <code>www.mysite.com/mypath/test/page-two</code>. But right now all I can do is go to <code>index.cgi</code> or <code>index.cgi/fnord</code>. I can also go to <code>/test/</code>. What do I need to do to fix this?</p>