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.

25 Comments

  1. Paul

    http://StateofGameplay

    March 16th, 2009

    Do these changes still apply when using 1.8.1 with Android and experimental Blackberry Storm support?

  2. The best way I have found to test it in the browser is to use Safari and change the user agent or use Firefox with the UserAgent Switcher extension and switch it to iphone.

  3. Yeah! It’s working fine for me too!

  4. Wes

    http://www.wesleyevans.net

    March 25th, 2009

    The above rule only covers iPhone. To allow support for all mobile devices that WPtouch supports you need to add this line instead:

    RewriteCond %{HTTP_USER_AGENT} !^.+(iPhone|iPod|aspen|dream|incognito|webmate|BlackBerry9500|BlackBerry9530)

    Please note that this list came directly from WPtouch.php ver 1.8.4. You should also add ALL of these devices to the list of rejected user agents in the WP Super Cache admin.

  5. Gilles

    http://www.chillez.com

    April 10th, 2009

    Yeah, working for me too. Note that I have excluded the full list of user agents but was only able to test iPhone. Thanks!

  6. Thanks for this tip- am running Super Cache and seeing everything correctly on iPhone.

  7. thankz for info. i just try this plugin :)

  8. My website does not work with internet explorer if i activate supercache and WPtouch?? How come??

    I even tried only with supercache and WPtouch plugin activated only, and still the same problem, i did as described above and my site loads great on iPhone, Firefox, Google Chrome and so on, but not on internet explorer, what can be the problem in this case?

  9. jim

    May 14th, 2009

    Putting this in as a rule in my htaccess file lead to 404 pages:

    RewriteCond %{HTTP_USER_AGENT} !^.+(iPhone|iPod|aspen|dream|incognito|webmate|BlackBerry9500|BlackBerry9530)

  10. Gravity

    http://pwnwear.com

    January 31st, 2010

    Is this mod still required in some fashion? Latest version of supercase includes ‘iphone’ in its list already.