Q:

Redirecting App Engine subdomains to folders

I'm hosting an application on Google App engine and have multiple static pages, that I would like to serve on its own subdomain. 
So if the domain is example.com I would like page.example.com/file to serve the file example.com/page/file. This would be a simple task if it was hosted on an apache server with rewrites. 
App Engine provides a tutorial for simulating mod_rewrite in php, but this redirects to other scripts on the page, and not static files, meaning that the static files would not be served as being static. Instead of reading the files in the php script, it would also be possible to do a redirect to the static resource, but that would mean that the URL would change for the user, and they would see example.com/page/file in their address bar, I would like to avoid this.
In app.yaml I can do simple rewrites, but only on the part after the domain, and not do the subdomain -> directory substitution.

A:

Note that using the mod_rewrite emulation means you'd no longer serve the file as static content, you'd be serving it dynamically, potentially eating into your instance hours.
One approach still using static serving would be to map your app/service as both example.com and page.example.com and present your static dir in 2 places in your app.yaml file's handlers section, something like this:
- url: /(<file_pattern_here>)$
  static_files: static/\1
  upload: static/<file_pattern_here>$

- url: /page/(<file_pattern_here>)$
  static_files: static/\1
  upload: static/<file_pattern_here>$

But note that it would also work for page.example.com/page/file. If you don't like that you could create a second service, let's call it page and then you'd split the job:

the old service (default?), mapped to example.com responds to example.com/page/file requests via this handler:
- url: /page/(<file_pattern_here>)$
  static_files: static/\1
  upload: static/<file_pattern_here>$

the new page service, mapped to page.example.com responds to page.example.com/file requests via this handler:
- url: /(<file_pattern_here>)$
  static_files: static/\1
  upload: static/<file_pattern_here>$

To keep the contents of the static directories in sync between the 2 services you should always deploy on both of them and only have one static dir sym-linked into the 2 services as needed, maybe something like this:
app/
app/static/
app/default/
app/default/static -> ../static
app/page/
app/page/static -> ../static

