Problem with WordPress using HTTPS

I have a WordPress site on a Windows server using IIS, that is using an HTTPS address served from our load balancer. When the site was using just http and no load balancer, it worked fine. Now, none of my stylesheets or other assets are loading on the front end (they say http instead of https), and when I try to login to the WordPress dashboard (wp-admin), I get an error that says the site "redirected too many times".

I have updated the site and WordPress URLs to HTTPS in my WP database. And, I have tried adding various code to my wp-config.php file, along with some rewrite rules to my web.config file but nothing seems to work.

Here are the various lines of code I have tried in my wp-config.php file:

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

Open in new window


if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'){
	 $_SERVER['HTTPS']='on';
	 $_SERVER['SERVER_PORT'] = 443;
}

Open in new window


define('FORCE_SSL_ADMIN', true);

Open in new window

define('FORCE_SSL_LOGIN', true);

Open in new window


I cannot figure out why the dashboard login won't load, and the front end assets only load with http??
kenjpeteAsked:
Who is Participating?
 
Martin MillerConnect With a Mentor CTOCommented:
Validate Internal network to Wordpress, and bypass NAT or SSL termination from Load Balancer.
0
 
Martin MillerCTOCommented:
You may have two problems...

Can you isolate to one? e.g.

-  let HTTP: pass through the load balancer to HTTP on your WordPress site?

Then you can confirm pass through with HTTP works with WordPress.

After that you can may one change at a time for HTTPS/SSL, like terminate SSL on the load balancer and use HTTP to WordPress.
0
 
kenjpeteAuthor Commented:
I'm not sure I fully understand what you are suggesting, but I don't have access to the load balancer on our network. Is there anything I can do from the WordPress side to isolate the problem?
0
 
kenjpeteConnect With a Mentor Author Commented:
Looks like things are working as they should now. Your solution of validating traffic from our load balancer to our WordPress server turned out to be the right place to look.

As it turns out the internal traffic from our load balancer to our WP server was going over port 443 but it was http, not https. So the script I added to wp-config.php wouldn't work because the forwarded protocol from our load balancer was http, not https, which is why my original IF/THEN statement never tested as true. See code below:

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

Open in new window


Once I changed it to the code below it worked like a charm:

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

Open in new window


thanks!
0
 
Martin MillerCTOCommented:
Awesome, glad you have this resolved!

Martin
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.