WordPress, HTTPS, CDN and W3 Total Cache

I’ve worked with a few sites recently that use HTTPS to secure certain parts of there site and also a couple of pages here are SSL protected due to the data captured. If you use the W3 Total Cache plugin like I do, and I really recommend that you do if you have a wordpress site, and make use of its CDN functionality, you might hit the following snag:

My CDN provider doesnt provide a HTTPS endpoint or its different to my normal CDN URL

the simple solution to this would be, to force loading of cdn assets via HTTP like so:

 

 

 

 

This has one other issue

Why dont i see the Blue/Green Bar?

That’s because your loading HTTP assets on a HTTPS page, for some this is an acceptable tradeoff. but for some this is bar is a must to convey trust to users. Thankfully the solution is fairly simple, Disable the CDN on SSL pages. To disable the CDN on SSL pages only add the following code snippet to your themes functions.php file, this snippet requires the W3TC plugin to be enabled and working to work as its code that tells W3TC: “hey, don’t load the cdn on this page!”

[code]add_action(‘wp_head’,’nocdn_on_ssl_page’);
function nocdn_on_ssl_page() {
if ($_SERVER[‘HTTPS’] == “on”) {
define(‘DONOTCDN’, true);
}
}[/code]

reload an SSL page and watch the address bar and do a view source to see the results!

Posted in General, Security
Tags: , , , , , , ,
4 comments on “WordPress, HTTPS, CDN and W3 Total Cache
  1. thanks! i was banging my head against the keyboard on this one. maxcdn doesn’t seem to support ssl in their pull zones and we’re running ecommerce!

  2. Thank you so much! This had been driving me crazy. I knew I had a problem with the WordPress HTTPS plugin but I couldn’t tell if the conflict was with Gravity Forms or W3TC. Searching the latter brought me here – what a simple, elegant solution.

  3. AJ says:

    Any update on this?

    W3TC –> CDN –> Advanced –> Disable CDN on SSL pages: simply does not work. Pages still get broken with mixed content warnings.

    I realise this is an old thread, but if you could assist, I’d sure be appreciative.

    Our’s is a WooCommerce site and we’re using CloudFlare’s SSL Cert and (formerly) using MaxCDN, but had to cancel because they (MaxCDN) could not conjure a fix and W3TC’s ‘support’ is non-existent.

    In fact, MaxCDN recommended we switch to WP SuperCache since they had no answers to the problem. Unfortunately, WP SuperCache does not work with WooCommerce sites.

    Needless to say, I (as the developer) am very frustrated and would appreciate your input.

1 Pings/Trackbacks for "WordPress, HTTPS, CDN and W3 Total Cache"
  1. […] previously mentioned some of the workarounds of using the excellent W3 Total Cache plugin with a CDN and utilising HTTPS on […]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.