Reputation: 404
All css and js load url http not https after apply ssl in my wordpress site. home page load proper but inner page not load proper because css and js path use http.
url use https.
Upvotes: 1
Views: 2858
Reputation: 65
If the web server is behind a proxy service, like squid or cloudflare,
// BEGIN NEW TWO LINES
} elseif ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && ( 'https' == $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) {
return true;
// END NEW TWO LINES
you can add these two lines inside of "is_ssl()" function in "wp-includes/load.php" file.
Finally you will get this:
/**
* Determines if SSL is used.
*
* @since 2.6.0
* @since 4.6.0 Moved from functions.php to load.php.
*
* @return bool True if SSL, otherwise false.
*/
function is_ssl() {
if ( isset( $_SERVER['HTTPS'] ) ) {
if ( 'on' === strtolower( $_SERVER['HTTPS'] ) ) {
return true;
}
if ( '1' == $_SERVER['HTTPS'] ) {
return true;
}
} elseif ( isset( $_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
return true;
// BEGIN NEW TWO LINES
} elseif ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && ( 'https' == $_SERVER['HTTP_X_FORWARDED_PROTO'] ) ) { // <== NEW
return true;
// END NEW TWO LINES
}
return false;
}
Upvotes: 1
Reputation: 2588
Add this to your wp-config.php
// Work out if we are using https
$isSecure = false;
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
$isSecure = true;
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
$isSecure = true;
}
$REQUEST_PROTOCOL = $isSecure ? 'https://' : 'http://';
define( 'WP_CONTENT_URL', $REQUEST_PROTOCOL.$_SERVER['HTTP_HOST'] . '/wp-content');
define( 'WP_HOME', $REQUEST_PROTOCOL.$_SERVER['HTTP_HOST'] );
And make sure all your CSS and JS is using the enque functions: https://codex.wordpress.org/Plugin_API/Action_Reference/wp_enqueue_scripts
Upvotes: 2