title: APP.YAML: Combine different URLs-same file, static file serving & source code access in app.yaml
body: <p>I now there are a lot of questions about app.yaml, and I searched and searched, but this one I couldn't find.</p>
  
  <p><strong>TLDR</strong>: PLEASE read full answer first, this isn't your standard application_readable:true. 
  <strong>I basically want to access the same file via different routes e.g. /static/img/pic.jpg AND /img/pic.jpg</strong></p>
  
  <h2>USE CASE</h2>
  
  <p>I build a flask application (upon the work of <a href="https://github.com/fsouza/gaeseries" rel="nofollow">fsouza</a> ) and i try to build a thumbnail extension for flask which will work on gae (because it's a read-only FS, I forked <a href="https://github.com/silentsokolov/flask-thumbnails" rel="nofollow">flask-thumbnails</a> and currently try to expand it.)</p>
  
  <h2>So I need:</h2>
  
  <ul>
  <li>access to my static files via python so I can read the img and make thumbnails on the fly. 
  URL is eg. <strong>/STATIC/IMG/PIC.JPG</strong></li>
  <li>still deliver other images, css, js via app.yaml. 
  URL is eg. <strong>/IMG/PIC.JPG</strong></li>
  </ul>
  
  <h2>What's not working:</h2>
  
  <p><strong>It's working locally</strong>, won't work after deploying. I thinks app.yaml is not so strictly enforced by dev_appserver.py as it should.</p>
  
  <p>I can either get one of this scenarios to work. This is how my app.yaml currently looks:</p>
  
  <pre><code>builtins:
  - appstats: on
  - admin_redirect: on
  - deferred: on
  - remote_api: on
  
  - url: /css
    static_dir: application/static/css 
  
  - url: /js
    static_dir: application/static/js 
  
  - url: /img
    static_dir: application/static/img
  
  - url: /static
    static_dir: application/static
    application_readable: true
  
  - url: .*
    script: run.application.app
  </code></pre>
  
  <p>I also tried this instead:</p>
  
  <pre><code>- url: /css/(.*)
    static_files: css/\1
    upload: css/(.*) 
  
  - url: /js/(.*)
    static_files: js/\1
    upload: js/(.*) 
  
  - url: /img/(.*)
    static_files: img/\1
    upload: img/(.*) 
  </code></pre>
  
  <p>When I comment the specific js,css,img stuff out, the application can access the img in application/static/img and make a thumbnail out of it. But the urls with e.g. /img/dont.need.thumbnail.jpg won't be served.</p>
  
  <p>When I comment this part:</p>
  
  <pre><code>- url: /static
    static_dir: application/static
    application_readable: true
  </code></pre>
  
  <p>img,css,js get served like they should.</p>
  
  <p>Can anybody help me? What I'm doing wrong?</p>
  
  <p><strong><em>Are app.yaml urls recursive?</em></strong></p>
  
  <h2>Current Workaround:</h2>
  
  <p>My current workaround is, that I simply add several url route through in python application. But that is not efficient and I suspect it costs me more CPU time and is slower.
  e.g.</p>
  
  <pre><code>app.add_url_rule('/img/&lt;path&gt;', 'static_img_files', view_func=views.static_img_files)
  def static_img_files(path):
      return static_files("img/"+path)
  </code></pre>
  
  <p><strong>Bonus hint:</strong> </p>
  
  <p>If you just git push-to-deploy </p>
  
  <pre><code>application_readable: true
  </code></pre>
  
  <p>won't work, so the python application won't have access to the static images as soon as you test it on the gae servers and not locally anymore. you have to deploy it via the app engine launcher (this alone took me ages to find out)</p>