Search code examples
google-app-engineyaml

How to redirect all URLs with Google App Engine


How do I configure the app.yaml file to redirect all URLs to another URL? For example I want http://example.appspot.com/hello or http://example.appspot.com/hello28928723 to redirect to http://example.com.

I am only serving static files at the moment. Here is my app.yaml file:

application: testapp
version: 1
runtime: python
api_version: 1

handlers:
- url: (.*)/
  static_files: static\1/index.html
  upload: static/index.html

- url: /
  static_dir: static

Solution

  • you can redirect all requests easily with a python handler. Something like

    class FormHandler(webapp.RequestHandler):
      def post(self):
        if processFormData(self.request):
          self.redirect("http://example.com")