Wordpress get_template_directory_uri() returns http instead of https

前端 未结 7 1388
暖寄归人
暖寄归人 2021-02-19 03:32

We have recently applied SSL certificate on our website and we want all our url to have https:// protocol.

Once we moved our website to https://, our website broke down

7条回答
  •  粉色の甜心
    2021-02-19 03:43

    Going by this comment the initiator added:

    in my case we were using Load Balancer server and the SSL certificate was install on load balancer

    The answer from @pbond scratches the surface to the root cause of the issue. The WordPress is_ssl() function checks the $_SERVER['HTTPS'] and $_SERVER['SERVER_PORT'] to check if the current page is being accessed via https but the load balancer is most likely requesting your content on the non-SSL port 80.

    One good fix for this is to use the X-Forwareded-Proto HTTP header to figure out which protocol the client is actually using on the other side of the Load Balancer.

    With Apache 2.2, you could add this to your configuration:

    
      SetEnvIf X-Forwarded-Proto "^https$" HTTPS
    
    

    Another possible fix (alluded to by @Roberto Poblete but not explained) is to add this to wp-config.php

    if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
    $_SERVER['HTTPS'] = 'on';
    

    I have this to thank for sending me in the right direct

提交回复
热议问题