我有一个基于 gae 构建的应用程序。我使用 python 和 webapp2 框架。我需要进行 301 重定向www.my-crazy-domain.com to my-crazy.domain.com这样可以消除搜索结果中的 www 和非 www 双重内容。
有人有现成的解决方案吗?谢谢你的帮助!
我已经成功了。
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。解决方案是检查基本控制器中的请求,如果域不同则进行重定向。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)