简体   繁体   English

PHP 标头位置重定向到 http 而不是 https

[英]PHP header location redirect going to http instead of https

I am on aws lightsail for a dev server and beanstalk for a live server.我在开发服务器上使用 aws lightsail,在实时服务器上使用 beanstalk。 Lightsail has php 7.3 and beanstalk has 7.4. Lightsail 有 php 7.3,beanstalk 有 7.4。

I created a link that is then read in php and does a我创建了一个链接,然后在 php 中读取并执行

header('Location: /i/'.$res[0]['code'])

based on the url passed in.基于传入的url。

The initial link is like https://test.example.com/c/12ksskdad初始链接类似于https://test.example.com/c/12ksskdad

The link has a slightly different domain on the production beanstalk server and uses a different ssl cert.该链接在生产 beanstalk 服务器上的域略有不同,并使用不同的 ssl 证书。

If I redirect the link from the lightsail server, it redirects to https://test.example.com/i/adfadf which is correct.如果我从 Lightsail 服务器重定向链接,它会重定向到https://test.example.com/i/adfadf ,这是正确的。 if I redirect from the production beanstalk server, for certain browsers, especially iphone browsers, it redirects to http://test.example.com/i/adfadf .如果我从生产 beanstalk 服务器重定向,对于某些浏览器,尤其是 iphone 浏览器,它会重定向到http://test.example.com/i/adfadf

It redirects to http, instead of https.它重定向到 http,而不是 https。 I should be able to use the full url path to correct this, but we run from different urls and I don't want to do that if I don't have to.我应该能够使用完整的 url 路径来纠正这个问题,但是我们从不同的 url 运行,如果我不需要,我不想这样做。

Any ideas?有任何想法吗?

您可以检查您是否在 https $_SERVER["HTTPS"] 上,并且您可以使用 $_SERVER["SERVER_NAME"] 来传递实际的服务器名称,而无需对其进行硬编码:

header('Location: '. $_SERVER["HTTPS"] == 'on' ? 'https://' : 'http://' . $_SERVER["SERVER_NAME"] . '/i/'.$res[0]['code']);

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

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