本文介绍了重定向所有对 www 的请求.到根域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将来自 www.mysite.com 的所有请求重定向到 mysite.com

I need to redirect all requests coming from www.mysite.com to mysite.com

我找到了 rails 中的解决方案,但我如何在 Django/Python 中做到这一点?

I have found the solution in rails, but how can I do that in Django/Python?

我能找到的唯一解决方案(由 GoDaddy 的版主发布)就是上述解决方案.GoDaddy的DNS管理器好像解决不了这种问题.

The only solution I could find, which was posted by a moderator on GoDaddy was the above. Seems like I cannot resolve this kind of problem through the DNS Manager of GoDaddy.

推荐答案

已解决:

from django.http import HttpResponsePermanentRedirect

class WWWRedirectMiddleware(object):
    def process_request(self, request):
        if request.META['HTTP_HOST'].startswith('www.'):
            return HttpResponsePermanentRedirect('http://example.com')

这篇关于重定向所有对 www 的请求.到根域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 14:57