Google App Engine Python Webapp2 301从www重定向到非www域 [英] Google App Engine Python Webapp2 301 redirect from www to non-www domain

查看:147
本文介绍了Google App Engine Python Webapp2 301从www重定向到非www域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个建立在gae上的应用程序。我用webapp2框架来使用python。我需要将301从 www.my-crazy-domain.com 重定向到 my-crazy.domain.com ,以消除搜索结果中的www和非www双打。

I have an application built on gae. I use python with webapp2 framework. I need to make 301 redirect from www.my-crazy-domain.com to my-crazy.domain.com so to eliminate www and not-www doubles in search results.

有人有现成的解决方案吗?感谢您的帮助!

Does anybody have ready-to-use solution? Thanks for any help!

推荐答案

我做了这个诀窍。

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的主域。解决方案是检查基本控制器中的请求,并在域不同时重定向。

config.host_full contains my primary domain without www. Solution is to check request in base controller and made redirect if domain differs.

这篇关于Google App Engine Python Webapp2 301从www重定向到非www域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆