Heroku Django:重定向所有www请求。到根域 [英] Heroku Django: Redirect all requests for www. to root domain
问题描述
我需要将所有来自 www.mysite.com
的请求重定向到 mysite.com
我发现在rails中的解决方案,但我怎么能在django / python中做到这一点?
唯一的解决方案我可以罚款,这是主持人在GoDaddy上发布的是上述内容。似乎我无法通过GoDaddy的DNS管理器解决这类问题。
任何提示或想法?
提前致谢。
解决这个问题:
<$ p $ (自我,请求):
如果request.META [',
$ d
$ if b
$ process $ HTTP_HOST']。startswith('www。'):
return HttpResponsePermanentRedirect('http://mysite.com')
I need to redirect all requests coming from www.mysite.com
to mysite.com
I have found the solution in rails, but how can I do that in django/python?
The only solution I could fine, 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.
Any hints or thoughts?
Thanks in advance.
Solved whit this:
from django.http import HttpResponsePermanentRedirect
class WWWRedirectMiddleware(object):
def process_request(self, request):
if request.META['HTTP_HOST'].startswith('www.'):
return HttpResponsePermanentRedirect('http://mysite.com')
这篇关于Heroku Django:重定向所有www请求。到根域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!