How to 301 Redirect All Requests on Google App Engine

We need two files to set this up:

app.yaml is the configuration file for the app.
main.py is a redirect script.

app.yaml

application: your-app-name
version: 1
runtime: python27
api_version: 1
threadsafe: no

handlers:
– url: /.*
script: main.app

main.py

import webapp2

class MainPage(webapp2.RequestHandler):
def get(self):
self.redirect(“https://yourwebsite.com”, permanent=True)

app = webapp2.WSGIApplication([
(‘/.*’, MainPage),
], debug=True)