Webapp2 has a built-in redirect handler
No need to roll your own handler; webapp2 already comes with one.
application = webapp2.WSGIApplication([
webapp2.Route('/hello', webapp2.RedirectHandler, defaults={'_uri':'http://example.com'}),
webapp2.Route('/hello28928723', webapp2.RedirectHandler, defaults={'_uri':'http://example.com'}),
], debug=False)
The _uri argument is what the RedirectHandler class uses to define the destination. It took a lot of Google Fu to find the documentation on this but it works flawlessly in my app.
I assumed you're aware of this but you need to change your catch-all route from:
- url: /
static_dir: static
To (python27 version):
- url: /.*
script: main.application
Or: (pre python27 version)
- url: /.*
script: main.py
main.py
is the file containing the request handler + routes.
Note: There is no static-only way to handle redirects on GAE because of the nature of static files. Basically, there's no way to do a redirect in app.yaml
alone.