将多个域重定向到单个域django

时间:2019-02-27 15:25:49

标签: django

我不知道我将该代码放在哪里以及其他需要执行的操作。请向我解释=> https://djangosnippets.org/snippets/434/

from django.http import HttpResponseRedirect

class ValidateHostMiddleware(object):
    """
    In Apache's httpd.conf, you may have ServerName set to mysite.com.au along 
    with a number of aliases: mysite.com, mysite.net, my-site.com etc.

    This middleware redirects any request that isn't for mysite.com.au to that 
    domain, helping with SEO and brand recognition.
    """
    def process_request(self, request):
        if not request.META['HTTP_HOST'].endswith('mysite.com.au'):
            return HttpResponseRedirect('http://www.mysite.com.au/')

0 个答案:

没有答案