把你的appspot转向自定义域名
September 15, 2009
23:38 PM, Sep 15
GAE支持绑定自己的域名,所以很多用户都在使用自定义域名。和blogger.com不同,GAE绑定域名之后,原来的yourname.appspot.com并不会自动转向自定义域名。需要做301转向的话,可以使用以下的代码:
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 %s" % url] else: return wsgi_app(env, start_response) return redirect_if_needed
然后定义一下application:
from google.appengine.ext import webapp from google.appengine.ext.webapp import util ... def main(): application = webapp.WSGIApplication(ROUTES, debug = True) application = redirect_from_appspot(application) util.run_wsgi_app(application)
需要注意的是,如果启用了XMPP服务,在转向之后,XMPP不能正常工作。