Heroku Django:重定向所有www请求。到根域

编程入门 行业动态 更新时间:2024-10-27 11:28:08
本文介绍了Heroku Django:重定向所有www请求。到根域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

我发现在rails中的解决方案,但我怎么能在django / python中做到这一点?

唯一的解决方案我可以罚款,这是主持人在GoDaddy上发布的是上述内容。似乎我无法通过GoDaddy的DNS管理器解决这类问题。

任何提示或想法?

提前致谢。

解决方案

解决这个问题: <$ p $ (自我,请求):如果request.META [', $ d $ if b $ process $ HTTP_HOST']。startswith('www。'): return HttpResponsePermanentRedirect('mysite')

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

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('mysite')

更多推荐

Heroku Django:重定向所有www请求。到根域

本文发布于:2023-10-31 17:27:30,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   Django   Heroku   www   到根域

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!