Precautions for Deploying SSL on WordPress on Virtual Hosting (301 Redirect)
Published: 2018-03-02
Notes:
1. If your theme/plugin uses absolute addresses to call http requests, it may cause garbled text when the website opens, or the green lock icon may not appear. You need to contact the program provider to change all http requests to https
2. Because the identifier “$_SERVER['HTTPS']" used in the program to detect https is not enabled, it may cause loops when visiting the website, prevent logging into the backend, etc., and this detection identifier needs to be modified
3. Because wp-includes/load.php or wp-includes/functions.php , after automatically updating wordpress, these two files will be restored, which may cause page disorder. You need to modify the corresponding files again according to this tutorial
First refer to: Virtual Host SSL Certificate (https) Deployment Process to complete SSL deployment.When deploying, please check Force/Automatic redirect to https;
If after configuring https on a cloud server, wordpress backend cannot log in and prompts that you have been redirected too many times, you only need to add the following code at the beginning of wp-config.php in the website root directory to perfectly solve this problem:
$_SERVER['HTTPS'] = 'on';
define('FORCE_SSL_LOGIN', true);
define('FORCE_SSL_ADMIN', true);
After completion, log in to the WordPress backend - Settings - General - change the WordPress Address (URL)/Site Address (URL) address to the https format, as shown in the screenshot below.

After adding, use a browser to visit the website frontend and backend to test whether it is normal. If it is normal, you do not need to perform the following operations.
Some url addresses have already been written into the database and cannot be updated through the backend. You can use phpmyadmin or other management tools to replace http with https in the database (Before performing risky operations, be sure to first back up the database)
Continue to modify the file wp-includes/load.php or wp-includes/functions.php, search for is_ssl to find the corresponding function, and change $_SERVER['HTTPS'] to $_SERVER["HTTP_FROM_HTTPS"] (please be sure to back up before modifying files).

Or modify this function to:
function is_ssl() {
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'){
return true;
}
elseif (isset($_SERVER["HTTP_FROM_HTTPS"])&&$_SERVER["HTTP_FROM_HTTPS"]=='on'){
return true;
}
elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'){
return true;
}
else{
return false;
}
}Finally refer to: Set up a 301 redirect after deploying https(ssl) to redirect http to https
