1

It works on our home page. so if you go to www.domain.com or http:// www.domain.com it will force you to https://. So that works.
But if you go directly to http:// www.domain.com/about-us it won't force you back to https. If you go to https:// www.domain.com/about-us it works fine. But You have to manually put the 's' in.

I'm running the 'Wordpress HTTPS (SSL)' plugin.

In my htaccess I have:

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI}

And in my wp-config I have:

define('WP_HOME','https://www.domain.com');
define('WP_SITEURL','https://www.domain.com');

define('FORCE_SSL_ADMIN', true);

if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
       $_SERVER['HTTPS']='on';

EDIT WITH SOLUTION

I'm not going to mark this as solved since I don't know why this solution worked for me, as the code should actually work the way I have it based on everything I've read from here and from Amazon concerning their ELBs. The important thing to remember that the X-Forwarded-Proto is the key here and is the header passed through the ELB. https://aws.amazon.com/premiumsupport/knowledge-center/redirect-http-https-elb/

I ended up moving the RewriteCond & RewriteRule from the .htaccess to my .conf file and everything is working now as expected.

  • Use the Recommended .htaccess CODE from here: wordpress.stackexchange.com/a/256042/110572 and remove the if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) CODE from your wp-config.php. – Fayaz Feb 14 '17 at 0:59
  • 1
    Thanks for the link. My issue is, I need the if statement. Since my AWS load balancer is stripping out the HTTPS and communicating to the back end server via HTTP. Without the IF it doesn't work correctly. – Matt Winer Feb 14 '17 at 4:34
  • 1
    Ah, OK, got that. However, in that case, $_SERVER['HTTP_X_FORWARDED_PROTO'] may not even be set. Check with isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) in the if condition first. – Fayaz Feb 14 '17 at 4:54
  • @Fayaz sorry, I'm playing catch up here. Using the your recommended code from the link I see you are forwarding from http://www.ex.com to https://ex.com. We'd like to keep it at www, but also we have qa.ex.com for testing. Right now it strips of the "qa" and redirects to https://ex.com. All the https is working on the back end just still not redirecting http://qa.ex.com/about to https://qa.ex.com/about – Matt Winer Feb 14 '17 at 5:32
  • Since your load balancer is communicating with http, those rules may not work anyway. Best if you can redirect users from the load balancer. In case that's not possible, then you'll have to check what variable your load balancer is forwarding to detect the scenario properly. Here you'll find a similar case with CloudFlare: stackoverflow.com/a/20419821/854549 – Fayaz Feb 14 '17 at 5:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.