Title: Separate caches for HTTP and HTTPS
Last modified: August 22, 2016

---

# Separate caches for HTTP and HTTPS

 *  [Arno Welzel](https://wordpress.org/support/users/awelzel/)
 * (@awelzel)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/separate-caches-for-http-and-https/)
 * My website can be accessed using http and https as well. I also have a content
   filter which takes care that all internal links will either use “[http://&#8221](http://&#8221);
   or “[https://&#8221](https://&#8221); to avoid problems with mixed protocols.
 * Unfortunately, Cachify does not include the protocol for the cache, so when a
   user accesses the site using http the cached version will have “[http://&#8221](http://&#8221);
   in all links. If another user visits the same URL later using https, he will 
   get the cached version with “[http://&#8221](http://&#8221); links, which will
   break a lot of things.
 * Therefore I extended Cachify to use an additional prefix for the cache folder
   so different versions for http and https are cached separately and can easily
   be used in Apache rewrite rules as well (I don’t use NGinx, but it should be 
   possible there as well).
 * 1) In inc/cachify.class.php
 *     ```
       private static function _cache_hash($url = '')
       	if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on') $prefix='443-';
       	else $prefix='80-';
       	return md5(
       		empty($url) ? ( $prefix . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ) : ( $prefix . parse_url($url, PHP_URL_HOST) . parse_url($url, PHP_URL_PATH) )
       	) . '.cachify';
       }
       ```
   
 * 2) In inc/cachify_hdd.class.php
 *     ```
       private static function _file_path($path = NULL)
       {
       	if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on') $prefix='443-';
       	else $prefix='80-';
   
       	$path = sprintf(
       		'%s%s%s%s%s',
       		CACHIFY_CACHE_DIR,
       		DIRECTORY_SEPARATOR,
       		$prefix,
       		parse_url(
       			'http://' . strtolower($_SERVER['HTTP_HOST']),
       			PHP_URL_HOST
       		),
       		parse_url(
       			( $path ? $path : $_SERVER['REQUEST_URI'] ),
       			PHP_URL_PATH
       		)
       	);
   
       	if ( validate_file($path) > 0 ) {
       		wp_die('Invalide file path.');
       	}
   
       	return trailingslashit($path);
       }
       ```
   
 * 3) Apache rewrite rules to send the cached content if available
 *     ```
       RewriteEngine On
   
       # GZIP FILE
       <IfModule mod_mime.c>
       RewriteCond %{REQUEST_URI} !^/wp-admin/.*
       RewriteCond %{REQUEST_METHOD} !=POST
       RewriteCond %{QUERY_STRING} =""
       RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_
       RewriteCond %{HTTP:Accept-Encoding} gzip
       RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/cachify/%{SERVER_PORT}-%{HTTP_HOST}/%{REQUEST_URI}/index.html.gz -f
       RewriteRule ^(.*) /wp-content/cache/cachify/%{SERVER_PORT}-%{HTTP_HOST}%{REQUEST_URI}/index.html.gz [L]
   
       AddType text/html .gz
       AddEncoding gzip .gz
       </IfModule>
   
       # HTML FILE
       RewriteCond %{REQUEST_URI} !^/wp-admin/.*
       RewriteCond %{REQUEST_METHOD} !=POST
       RewriteCond %{QUERY_STRING} =""
       RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_
       RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/cachify/%{SERVER_PORT}-%{HTTP_HOST}/%{REQUEST_URI}/index.html -f
       RewriteRule ^(.*) /wp-content/cache/cachify/%{SERVER_PORT}-%{HTTP_HOST}%{REQUEST_URI}/index.html [L]
       ```
   
 * [https://wordpress.org/plugins/cachify/](https://wordpress.org/plugins/cachify/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [podpirate](https://wordpress.org/support/users/podpirate/)
 * (@podpirate)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/separate-caches-for-http-and-https/#post-5927432)
 * Same issue for me.
    Will a donation help to get this fixed in the next version?
 *  [Pascal Birchler](https://wordpress.org/support/users/swissspidy/)
 * (@swissspidy)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/separate-caches-for-http-and-https/#post-5927433)
 * Hey [@awelzel](https://wordpress.org/support/users/awelzel/)
 * Thanks for your report! Although accessing a site over both HTTP and HTTPS isn’t
   really recommended, the plugin really doesn’t work in this scenario at the moment.
   We’re definitely going to look into this, so thanks for the work you already 
   did here!
 * There’s an issue on GitHub now where you can track progress: [https://github.com/pluginkollektiv/cachify/issues/2](https://github.com/pluginkollektiv/cachify/issues/2)
 * [@podpirate](https://wordpress.org/support/users/podpirate/): Donations are always
   welcome as we all do this in our spare time.
 * Can you tell me more about your setup? Which caching method do you use?
 *  Thread Starter [Arno Welzel](https://wordpress.org/support/users/awelzel/)
 * (@awelzel)
 * [10 years, 11 months ago](https://wordpress.org/support/topic/separate-caches-for-http-and-https/#post-5927434)
 * I just created a pull request for my supposed changes but with using is_ssl()
   instead of server variables.
 * This change works live on my website [http://arnowelzel.de](http://arnowelzel.de)(
   and of course [https://arnowelzel.de](https://arnowelzel.de) ;-)).

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Separate caches for HTTP and HTTPS’ is closed to new replies.

 * ![](https://ps.w.org/cachify/assets/icon-256x256.png?rev=2505413)
 * [Cachify](https://wordpress.org/plugins/cachify/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cachify/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cachify/)
 * [Active Topics](https://wordpress.org/support/plugin/cachify/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cachify/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cachify/reviews/)

## Tags

 * [HTTPS](https://wordpress.org/support/topic-tag/https/)
 * [SSL](https://wordpress.org/support/topic-tag/ssl/)
 * [TLS](https://wordpress.org/support/topic-tag/tls/)

 * 3 replies
 * 3 participants
 * Last reply from: [Arno Welzel](https://wordpress.org/support/users/awelzel/)
 * Last activity: [10 years, 11 months ago](https://wordpress.org/support/topic/separate-caches-for-http-and-https/#post-5927434)
 * Status: not resolved