How can I redirect 500 Errors from google appengine to another location.
The following is an example scenario:
All requests to http://example.appspot.com/testfile.ext in case of a 500 error should redirect to http://www.example.com/testfile.ext
This is basically combining the 500 er开发者_StackOverflowror with a 302 redirect. Is it possible if not is there a work around?
It can redirect a failure with simplest way I know
try:
#stuff
except:
self.redirect('http://www.example.com/testfile.ext')
return
Or this slightly more complicated redirect one can modify from 301 to 302
def redirect_from_appspot(wsgi_app):
def redirect_if_needed(env, start_response):
if env["HTTP_HOST"].startswith('my_app_name.appspot.com'):
import webob, urlparse
request = webob.Request(env)
scheme, netloc, path, query, fragment = urlparse.urlsplit(request.url)
url = urlparse.urlunsplit([scheme, 'www.my_domain.com', path, query, fragment])
start_response('301 Moved Permanently', [('Location', url)])
return ["301 Moved Peramanently",
"Click Here" % url]
else:
return wsgi_app(env, start_response)
return redirect_if_needed
Case depends if 500 Error is your app or google server. Easiest would be featuring it in gae console we can request app engine team to enable, or yaml or most formal with regex. The easy way is try, except and redirect.
精彩评论