WPtouch and WP Super Cache

by Duane Storey ~ Jan 05 / 2009

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.

23 Comments

  1. Made the suggested changes and it seems to work on my individual posts, but not on my actual homepage. Does WPtouch do anything to the homepage (I’ve just barely installed it so I’m not sure if it is supposed to off-hand, I would assume so). Other than the homepage though it seems to be working fine from both the browser and the iPhone ;)

  2. Dale Mugford

    BNC Design Guru

    1 year, 2 months Reply

    Did you clear your cache (in the admin, in your browser, and on the iphone/ipod touch)?

  3. Everything seems to be working with the fixes but how do you get the plugin to work again after clicking on the “view normal” ?

  4. Dale Mugford

    BNC Design Guru

    1 year, 1 month Reply

    It should automatically insert footer links into your regular theme that allow for switching back to WPtouch. If they’re not there, you’re likely missing WordPress code in your footer.

    Visit the WPtouch page and read up on the ‘Template Switch Code’ section of the documentation.

  5. This worked for me after I cleared the cache. Thanks for a great plugin!

  6. This is not working for me. I love this plugin. I thought it was working fine, which it was briefly, but then when I cleared my iPhone cache, it has never returned. My iPhone must have loaded the WPtouch page before Super Cache was on. :-(
    Now I am left with it not working.
    Any work arounds would be greatly appreciated!

    Thanks.

  7. Duane Storey

    BNC Development Guru

    1 year, 1 month Reply

    @KirklandViews did you also add the user agent strings to the WP-Super Cache adminstration panel?

  8. Steve Cloke

    1 year, 1 month Reply

    Awesome plug-in!!
    I did as you suggested above and seems to be working fine :-)
    Cheers.

  9. It’s working fine for me

    Thank you very mmuch

  10. This seems to work fine for me!

    I have a question though-is there a direct URL to the mobile site? (Like if I want to check it out on my regular desktop)? If so, what is the link address?

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

  12. 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.

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

  14. 11 months, 3 weeks Reply

    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.

  15. 11 months, 1 week Reply

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

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

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

  18. 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?

  19. jim

    10 months Reply

    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)

  20. 1 month, 1 week Reply

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

  21. Seems it works for me!
    Thanks!

Leave a Reply


One of 525 websites proudly supporting Earth Hour. On WordPress? Get the plugin.