Enable SSL on AWS Lightsail in wordpress
Add the below code:
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on';
in your wp-config.php file below the line. /* That’s all, stop editing! Happy publishing. */ and replace the below code:
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/');
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/');
with this code:
define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST'] . '/');
define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST'] . '/');
And add the below code at the end in your functions.php file in your wordpress theme so that all your http requests redirected to https
add_action('template_redirect', 'redirect_core', 50);
add_action('init', 'redirect_core', 50);
add_action('wp_loaded', 'redirect_core', 50);
function redirect_core(){
if (!is_ssl()) {
wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 301);
exit();
}
}
And you are done. Enjoy 🙂