简体   繁体   English

指定 HTTP 或 HTTPS 时 Django 重定向不起作用

[英]Django redirect not working when specifying HTTP or HTTPS

I am not sure why this is happening, but when I specify HTTP or HTTPS as my full URL in a redirect, the part after my domain name is appended to my current domain.我不确定为什么会发生这种情况,但是当我在重定向中指定 HTTP 或 HTTPS 作为我的完整 URL 时,我的域名后面的部分会附加到我的当前域中。

For example: if I redirect to https://www.external_site.com/error/page/hi_there.html it will go to https://www.currentdomain.com/error/hi_there/html例如:如果我重定向到https://www.external_site.com/error/page/hi_there.html它将转到https://www.currentdomain.com/error/hi_there/html

return redirect('https://www.external_site.com/error/page/hi_there.html')

But, when I remove the https: part (but leave the //), the redirect works as expected:但是,当我删除 https: 部分(但保留 //)时,重定向按预期工作:

return redirect('//www.external_site.com/error/page/hi_there.html')

I am using Django v 1.11.23 but also tested it on Django 2.我正在使用 Django v 1.11.23,但也在 Django 2 上对其进行了测试。

Django runs on Apache on mod_wsgi, and goes through an IIS reverse proxy (the reverse proxy is just a reverse proxy in this instance, no special rules or anything besides to rewrite the external domain to the internal domain.) Django 在 Apache 上的 mod_wsgi 上运行,并通过一个 IIS 反向代理(反向代理在这种情况下只是一个反向代理,除了将外部域重写为内部域之外,没有特殊规则或其他任何东西。)

I found the issue.我发现了这个问题。

It is related to "IIS reverse rewrite host in response headers" ARR setting.它与“响应标头中的 IIS 反向重写主机”ARR 设置有关。 I disabled it by going to "IIS Manager -> Machine or Site (I used Machine so it applies to all sites) -> Application Request Routing Cache -> Server Proxy Settings and uncheck the "Reverse rewrite host in response headers" checkbox“我通过转到“IIS 管理器 -> 机器或站点(我使用机器,因此它适用于所有站点) -> 应用程序请求路由缓存 -> 服务器代理设置并取消选中“响应标头中的反向重写主机”复选框来禁用它“

Now it is working as it should.现在它正在正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM