-
Create a backup copy of your site and your database!
-
I reccomend starting with a plugin that manages all of this stuff for you, but if it doesn't work keep reading! :D
-
Add these lines to to
wp-config.php
filedefine('FORCE_SSL_ADMIN', true); if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on';
Make sure you add them before this line:
require_once(ABSPATH . 'wp-settings.php');
-
Update the
wp-config.php
filedefine('WP_HOME','https://www.example.com/'); define('WP_SITEURL','https://www.example.com/');
-
Sometimes we have plain hard-coded
http
protocols, to fix that we have to create wrappers for thewp_head()
andwp_footer
. So, just call these new functions instead. I recommend using something likegrep -rnw './' -e "wp_head"
so you know all of the places where this function is being called./** * Wrapper for wp_head() which manages SSL * * @uses wp_head() * @param bool $ssl * @return void */ function custom_wp_head() { // Capture wp_head output with buffering ob_start(); wp_head(); $wp_head = ob_get_contents(); ob_end_clean(); // Replace plain protocols $wp_head = preg_replace( '/(["\'])http:\/\//', '\1https://', $wp_head ); // Output echo $wp_head; } function custom_wp_footer() { // Capture wp_head output with buffering ob_start(); wp_footer(); $wp_footer = ob_get_contents(); ob_end_clean(); // Replace plain protocols $wp_footer = preg_replace( '/(["\'])http:\/\//', '\1https://', $wp_footer ); // Output echo $wp_footer; }
Created
May 4, 2017 21:32
-
-
Save mrtrom/dc5483a2f2546e649885ac32d02102f6 to your computer and use it in GitHub Desktop.
Migration a Wordpress site from HTTP to HTTPS
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment