简体   繁体   中英

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. Lightsail has php 7.3 and beanstalk has 7.4.

I created a link that is then read in php and does a

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

based on the url passed in.

The initial link is like https://test.example.com/c/12ksskdad

The link has a slightly different domain on the production beanstalk server and uses a different ssl cert.

If I redirect the link from the lightsail server, it redirects to https://test.example.com/i/adfadf which is correct. if I redirect from the production beanstalk server, for certain browsers, especially iphone browsers, it redirects to http://test.example.com/i/adfadf .

It redirects to http, instead of 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.

Any ideas?

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

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

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