I use WPEngine as my development environment for client sites. Using git to push code changes and Migrate DB Pro to push content changes makes development a breeze.
There is one small quirk that I’ve noticed. WPEngine forces SSL on the backend, but lets you use either http or https on the frontend. Even if you set all the URLs in your site to https, if you type in the http version of the URL you are not redirected. This isn’t an issue on production sites because you can customize the SSL settings, but for transferrable or staging installs the SSL page is inaccessible.
This can be a bit confusing to clients if they type in the URL and no longer see the “Secure” message in their browser. But it can also cause technical issues with the site. If you’re using admin-ajax for anything – for instance, sending emails in EA Share Count – these won’t work because there’s a domain mismatch.
You could install a plugin that forces SSL, but I worry I’d forget to deactivate the plugin before launching the site in an environment where the client doesn’t already have SSL setup.
Instead, I use the following code. This can be added to your core functionality plugin or a standalone plugin.
<?php | |
/** | |
* Force SSL on WPEngine install | |
* | |
* @author Bill Erickson | |
* @see https://www.billerickson.net/force-ssl-on-wpengine | |
* | |
*/ | |
function be_force_ssl_on_wpengine() { | |
if( strpos( home_url(), 'wpengine' ) && ! is_ssl() ) { | |
wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 301 ); | |
exit(); | |
} | |
} | |
add_action( 'template_redirect', 'be_force_ssl_on_wpengine' ); |
Melanie Adcock says
Bill,
This is so awesome. I also use WPE and had the very issue.
Thanks!
Melanie
Craig says
Have had this same issue many times at WPE.
Will give this a shot. Thanks!!
Jon Brown says
Lol, I was literally try the get http>Https redirects set via the WPE portal working an hour ago… I didn’t succeed, so I’ll give this a try.
Christine says
Thank you!
Peter Wise says
Hey – works great – thank you!
The only thing I would add is since SEO is not a consideration on a staging site, you might do a 302 instead of a 301 redirect. This won’t get cached by the browser, which can be annoying if you’re trying to go back to allowing http:// for any reason in the future. Or if something is wrong with the code or your setup you don’t endup with broken redirects cached.
Meredith says
Worked on my staged site on WP Engine (wanted to update because you posted this 3 years ago). I needed to test a payment gateway, but it wouldn’t let me test it unless there was a secure connection. Much appreciated!
Bill Erickson says
Thank you!