[SOLVED] Twig base_url() returns port 80 when used over HTTPS connection


#21

Had the same issue, this is my approach:

$this->container->share('environment', function () {

            $server = $_SERVER;

            // fix the secure environment detection if behind an AWS ELB
            if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
                $server['HTTPS'] = 'on';
                $server['SERVER_PORT'] = 443;
            }

            return new Environment($server);
        });

When you create the environment simply adjust those settings, and then all Slim methods should return the correct urls, incl https scheme and without port.

Hope this helps someone :slight_smile: