I'm working on a GAE application which largely consists of static content. I've configured the following handlers:
- url: /content/(.*\..*)
static_files: static/content/\1
upload: static/content/(.*)
- url: /content/(.+)
static_files: static/content/\1.html
upload: static/content/(.*)\.html
The first handler is used to serve images, stylesheets, etc.; the second handles plain URLs like /content/zoo/monkeys/george
and serves a corresponding HTML file.
Right now, GAE is returning an empty page if there is no corresponding static file for a URL. I'd like to set up a custom 404 page for these cases, but apparently this is not straightforward.
Answers to similar questions suggested putting a "catch-all" handler on the bottom of my app.yaml
, with a RequestHandler
that generates the error page.
However, /content/(.+)
matches all URLs under /content/
, valid or not, which means such a handler won't get invoked.
I can only think of two other solutions:
- Route all requests through a dynamic handler, which writes out content for valid URLs, or an error page for invalid ones. I don't like this, because it is far less efficient than letting GAE serve the static files.
- Declare a separate static handler that explicitly matches each static file, and then put a "catch-all" handler at the bottom -- I don't like this either, because it would result in a long list of handlers.
Is there another way to set up a proper 404 page for this case?