How do I redirect www to non-www in Google App Engine

雨燕双飞 提交于 2020-01-07 06:15:02

问题


My domain is bought from Godaddy and migrated to Amazon AWS. Previously we were using AWS and hosted our static website in AWS bucket but recently we moved to Google cloud platform and hosted our static website and wp blog in app engine. We manage our DNS in Amazon Route 53 and point dns to GAE. The problem is that our website can be browsed with both www and non www domain. Here, We wanted to redirect all the www to non-www domain. This cannot be done in Route 53 because we have pointed dns to GAE and added example.com as A record and www.example.com as CNAME. Thus this also doesn't solves the problem. We are not much sure how to write code in app.yaml file to redirect. We have searched a lot but haven't found any solution yet.


回答1:


Try python handler using which you should be able to redirect all your requests easily:

Something like below:

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


来源:https://stackoverflow.com/questions/39631712/how-do-i-redirect-www-to-non-www-in-google-app-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!