我有一个基于 gae 的应用程序。我将 python 与 webapp2 框架一起使用。我需要将 301 从 www.my-crazy-domain.com 重定向到 my-crazy.domain.com 以便消除搜索结果中的 www 和 not-www double .
有人有现成的解决方案吗?感谢您的帮助!
最佳答案
我成功了。
class BaseController(webapp2.RequestHandler):
"""
Base controller, all contollers in my cms extends it
"""
def initialize(self, request, response):
super(BaseController, self).initialize(request, response)
if request.host_url != config.host_full:
# get request params without domain
url = request.url.replace(request.host_url, '')
return self.redirect(config.host_full+url, permanent=True)
config.host_full 包含没有 www 的主域。解决方案是检查基本 Controller 中的请求,如果域不同则进行重定向。
关于python - Google App Engine Python Webapp2 301 从 www 重定向到非 www 域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26332234/