author image
WPtouch and WP Super Cache
Jan 5 2009 • Written By Duane Storey • 25 Comments

One request we hear over and over from the users of WPtouch is for WPtouch to somehow be able to work along side the WP Super Cache plugin. WPtouch has always been able to work when WP Super Cache is in half-on mode (which basically makes it the equivalent of the WP Cache plugin), and where the word “iPhone” is added to the list of rejected user agent strings. Unfortunately, it’s never quite worked properly when WP Super Cache is in full-on mode.

Running WP Super Cache in full-on mode actually bypasses WordPress in a lot of cases, and serves a cached version of the web page instead. This leads to problems with WPtouch and inconsistent behaviour, since sometimes a cache file from the normal web version is shown to a WPtouch user.

There are a few different ways to address this problem, and we might take a stab at adding an option in the WPtouch back-end at some point to help deal with this. A temporary solution (in theory) is to add this line to your .htaccess file in the two sections where WP Super Cache modifies it:

RewriteCond %{HTTP_USER_AGENT} !^.+iPhone

You can see a full example here:


# BEGIN WPSuperCache

RewriteEngine On
RewriteBase /
AddDefaultCharset UTF-8
RewriteCond %{REQUEST_URI} !^.*[^/]$
RewriteCond %{REQUEST_URI} !^.*//.*$
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$
RewriteCond %{HTTP_USER_AGENT} !^.+(iPhone|iPod|aspen|dream|android|BlackBerry9500|BlackBerry9530)RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -f
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz [L]

RewriteCond %{REQUEST_URI} !^.*[^/]$
RewriteCond %{REQUEST_URI} !^.*//.*$
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$
RewriteCond %{HTTP_USER_AGENT} !^.+iPhone
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html -f
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html [L]

# END WPSuperCache

This should cause the Super Cache portion of WP Super Cache to bypass the static cached files whenever it is accessed by an iPhone. You will still need to add the iPhone word to the list of rejected user agents in the WP Super Cache admin.

If you have success with this method, please let us know as we’ve only done limited testing with it.