Elastic Beanstalk - PHP / Force HTTPS
amazon-elastic-beanstalk, amazon-web-services, php
Solution
Beanstalk sets up their load balancer to send `X-Forwarded-Proto` headers to your instance(s).
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] !== 'https') {
// redirect to secure site
header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
}
Though, some will swear by not enabling HTTP at all, due to SSL stripping techniques used in MiTM attacks.
Having said that, you can mitigate SSL stripping by using HSTS.
Problem
How do I redirect all traffic while using Amazon Elastic Beanstalk with PHP from http to https? I have setup my Beanstalk to have a https port (all the certificate and stuff has been setup).