1

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?

1 Answer 1

1

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']);
Sign up to request clarification or add additional context in comments.

2 Comments

This is what I will probably end up doing. It is always going to be https so I don;t even need that check. I am in the middle of a lot of changes and did not want to have to do a code push. Was hoping it was some php setting.
They actually updated the load balancer to always serve https, which is working fine. I made the update that you recommended as well. Thanks for the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.