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?
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
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.
For GAE/J, add the following to your web.xml file.
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
www.example.com/test/
will now serve www.example.com/test/index.html
- url: /demos(/.+|)/
static_files: demos\1/index.html
upload: demos/(.+/|)index\.html
- url: /demos/
static_dir: demos
精彩评论