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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With