Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default document in Google App Engine

Is it possible to specify the equivalent of a default document for directories in Google App Engine so that navigating to that directory automatically redirects to its index.html for example, if it contains one?

If I have this in my app.yaml:

- url: /demos
  static_dir: demos

and the demos directory contains an index.html page, how can I tell App Engine to automatically redirect to that page?

like image 871
dezfowler Avatar asked Jul 03 '11 22:07

dezfowler


2 Answers

App Engine uses regular expression matches on the request path to determine what script to call or document to serve. If you just have the one index document, you can do it like this:

- url: /demos/
  static_files: demos/index.html
  upload: demos/index\.html

More generally, you can define static files for paths ending in slashes ('directories') like this:

- url: /(.*)/
  static_files: \1/index.html
  upload: .*/index\.html
like image 125
Nick Johnson Avatar answered Jan 04 '23 11:01

Nick Johnson


I got this to work by using this in my yaml.

- url: /(.+)
  static_files: static/\1
  upload: static/(.+)

- url: /
  static_files: static/index.html
  upload: static/index.html

Replace static with demos and you should be set. It redirects the blank domain to index.html and al others to the static folder.

like image 23
Gavin O Avatar answered Jan 04 '23 11:01

Gavin O