I have a GAE app serving static files defined by rules in the yaml file under two different domain names as configured in DNS, an old one and a new one, but otherwise it's the same content served for each. I'd like to redirect requests from the old domain to the new domain. I've seen this question, but that loses the ability to use the static asset handlers in the yaml from what I can tell, and would have to set up static asset serving explicitly in my main.py I think. Is there a simple way (ideally in the yaml file itself) to do a redirect when the hostname is the old domain, but keep my static file rules in place for the new domain?
Update
Here's a complete solution that I ended up using:
### dispatch.yaml ###
dispatch:
- url: "*my.domain/*"
module: redirect-module
### redirector.yaml ###
module: redirect-module
runtime: python27
threadsafe: true
api_version: 1
skip_files:
- ^(?!redirector.py$)
handlers:
# Redirect everything via our redirector
- url: /.*
script: redirector.app
### redirector.py ###
import webapp2
def get_redirect_uri(handler, *args, **kwargs):
return 'https://my.domain/' + kwargs.get('path')
app = webapp2.WSGIApplication([
webapp2.Route('/<path:.*>', webapp2.RedirectHandler, defaults={'_uri': get_redirect_uri}),
], debug=False)
Some extra docs: https://cloud.google.com/appengine/docs/python/modules/routing#routing_with_a_dispatch_file