WordPress.org

Ready to get started?Download WordPress

Forums

WP Super Cache
https vs http cache confusion - with solution (1 post)

  1. freerange
    Member
    Posted 1 year ago #

    Problem: Various core wordpres functions call is_ssl() when generating uri's - in particular all of the get_theme related functions do this. If a site is available on https and http then pages may be generated unpredictably with https:// or http:// internal links to stylesheets etc. A similar thing happens when behind amazon load balancers that send SSL traffic to port 80 except in this case the uri is always http: even when it should be https

    a page generated with http:// that gets cached and served to an a https: viewer will break due to non secure elements.

    Solution add to functions.php in your theme (or better still fold into wp_supercache)

    //Make URI's protocol agnostic
    add_filter( 'theme_root_uri', 'my_theme_root_uri');
    
    /**
     * Make uri's protocol agniostic
     **/
    function my_theme_root_uri($uri) {
    	return preg_replace("@^https?:@i","",$uri);
    }

    This will make all uri's returned by theme_root_uri() protocol agnostic allowing the page to work in either http or https (example "https://host.com/whatver" becomes "//host.com/whatever").

    See http://stackoverflow.com/questions/550038/is-it-valid-to-replace-http-with-in-a-script-src-http for more on uri's without a protocol part.

    http://wordpress.org/extend/plugins/wp-super-cache/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic