Automattic / Automattic/wp-super-cache
mod_rewrite never serving cache files if logged in status or mobile device
- Dominant language
- PHP
- Stars
- 436
- Forks
- 130
- Avg merge
- 15h 11m
- Merged PRs (30d)
- 10
Description
I've spent hours, days, months, maybe years, debugging Wp Super Cache and still it seems like I don't know the 10% of it.
What it seems that the plugin doesn't tell you and what I think I learnt by debugging it, is that while mod_rewrite promises to be super lighting fast by serving static html files without even passing from a line of PHP, this indeed is **not true**.
Let's study a **portion** from the simplest group of WPSC .htaccess rules you must install into .htaccess:
> RewriteCond %{HTTP:Cookie} !^._(comment_author_|wordpress_logged_in|wp-postpass_)._$
>
> RewriteCond %{HTTP_USER_AGENT} !^._(2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800)._ [NC]
>
> RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{SERVER_NAME}/$1/index.html -f
>
> RewriteRule ^(.*) "/wp-content/cache/supercache/%{SERVER_NAME}/$1/index.html" [L]
Note 1: these rules are fixed, regardless the wpsc dashboard options. Well, I tried changing the options such as enabling "mobile device support", but index-mobile.html never appeared in the rules. Turning on "make known users anonymous" also doesn't seem to take away the "wordpress_logged_in" string from the rule, correct me if I'm wrong.
So, the above (simplified subset) rules tell that:
**IF** ( the user is NOT logged in ) AND ( the device is NOT mobile )
**THAN** the server will serve a static html file from wpsc cache directory
**ELSE** let WP handle the request (aka wp-cache-phase1.php and so on)
So what if an user browse from a mobile device? The index-mobile.html file cache file will be potentially be served by PHP instead of mod_rewrite.
Same applies if the user is logged in.
Am I correct? Is this the intended behaviour?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the generated .htaccess rules and the WPSC dashboard options described in the report; compare the logged-in and mobile conditions with cache files under wp-content/cache/supercache. Check wp-cache-phase1.php to trace the fallback path. Done means determining whether index-mobile.html and logged-in requests are intentionally bypassed by mod_rewrite and documenting or correcting the behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- apache, php, wordpress
- Domain
- backend, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100