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?
CodePudding user response:
You can check that you are on https $_SERVER["HTTPS"] and you can use $_SERVER["SERVER_NAME"] to pass actual server name without hard coding it:
header('Location: '. $_SERVER["HTTPS"] == 'on' ? 'https://' : 'http://' . $_SERVER["SERVER_NAME"] . '/i/'.$res[0]['code']);