简体   繁体   中英

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.

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

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:

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 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.)

I found the issue.

It is related to "IIS reverse rewrite host in response headers" ARR setting. 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“

Now it is working as it should.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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