Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POST-Request to / receive a cached response (HDD-Cache) #200

Closed
uvoelkel opened this issue Oct 7, 2020 · 1 comment · Fixed by #258
Closed

POST-Request to / receive a cached response (HDD-Cache) #200

uvoelkel opened this issue Oct 7, 2020 · 1 comment · Fixed by #258

Comments

@uvoelkel
Copy link

uvoelkel commented Oct 7, 2020

With the Apache-rewrite rules provided by the plugins Setup tab POST request to / receive a (hdd) cached answer.

I'm not entirely sure what exactly goes wrong but it seems that after the final WordPress rule RewriteRule . /index.php [L] is applied, all the rewrite rules are checked again (which apparently is how apache works. did not know that before). inside the subrequest the REQUEST_METHOD seems not to match the initial one which leads to a cached response being delivered for a POST request to /

1 [Wed Oct 07 13:35:09.120411 2020] [rewrite:trace3] [pid 61:tid 140516971439872] mod_rewrite.c(483): [client 192.168.96.1:55700] 192.168.96.1 - - [localhost/sid#7fccb5d18420][rid#7fcca020e0a0/initial] [perdir /var/www/html/] applying pattern '.' to uri '', referer: https://localhost/
2 [Wed Oct 07 13:35:09.120417 2020] [rewrite:trace1] [pid 61:tid 140516971439872] mod_rewrite.c(483): [client 192.168.96.1:55700] 192.168.96.1 - - [localhost/sid#7fccb5d18420][rid#7fcca020e0a0/initial] [perdir /var/www/html/] pass through /var/www/html/, referer: https://localhost/
3 [Wed Oct 07 13:35:09.120473 2020] [rewrite:trace3] [pid 61:tid 140516971439872] mod_rewrite.c(483): [client 192.168.96.1:55700] 192.168.96.1 - - [localhost/sid#7fccb5d18420][rid#7fcca02020a0/subreq] [perdir /var/www/html/] strip per-dir prefix: /var/www/html/index.php -> index.php, referer: https://localhost/
4 [Wed Oct 07 13:35:09.120490 2020] [rewrite:trace3] [pid 61:tid 140516971439872] mod_rewrite.c(483): [client 192.168.96.1:55700] 192.168.96.1 - - [localhost/sid#7fccb5d18420][rid#7fcca02020a0/subreq] [perdir /var/www/html/] applying pattern '.*' to uri 'index.php', referer: https://localhost/
...
5 [Wed Oct 07 13:35:09.120627 2020] [rewrite:trace4] [pid 61:tid 140516971439872] mod_rewrite.c(483): [client 192.168.96.1:55700] 192.168.96.1 - - [localhost/sid#7fccb5d18420][rid#7fcca02020a0/subreq] [perdir /var/www/html/] RewriteCond: input='GET' pattern='!=POST' => matched, referer: https://localhost/
6 [Wed Oct 07 13:35:09.120634 2020] [rewrite:trace4] [pid 61:tid 140516971439872] mod_rewrite.c(483): [client 192.168.96.1:55700] 192.168.96.1 - - [localhost/sid#7fccb5d18420][rid#7fcca02020a0/subreq] [perdir /var/www/html/] RewriteCond: input='' pattern='=""' => matched, referer: https://localhost/
7 [Wed Oct 07 13:35:09.120640 2020] [rewrite:trace4] [pid 61:tid 140516971439872] mod_rewrite.c(483): [client 192.168.96.1:55700] 192.168.96.1 - - [localhost/sid#7fccb5d18420][rid#7fcca02020a0/subreq] [perdir /var/www/html/] RewriteCond: input='/index.php' pattern='!^/(wp-admin|wp-content/cache)/.*' => matched, referer: https://localhost/
...
8 [Wed Oct 07 13:35:09.120683 2020] [rewrite:trace2] [pid 61:tid 140516971439872] mod_rewrite.c(483): [client 192.168.96.1:55700] 192.168.96.1 - - [localhost/sid#7fccb5d18420][rid#7fcca02020a0/subreq] [perdir /var/www/html/] rewrite 'index.php' -> '/wp-content/cache/cachify/https-localhost/index.html.gz', referer: https://localhost/

line 1: is the final WordPress rule RewriteRule . /index.php [L]
which results in a subrequest (lines 2 and 3)
line 4 is the first cachify rule RewriteRule .* - [E=CACHIFY_HOST:https-%{HTTP_HOST}] this time applied to the subrequest to index.php
line 5 shows that for the subrequest the method is GET
6 & 7 are the cachify conditions
RewriteCond %{REQUEST_URI} !^/(wp-admin|wp-content/cache)/.*
RewriteCond %{HTTP_COOKIE} !(wp-postpass|wordpress_logged_in|comment_author)_
and in line 8 it gets rewritten to the cached path

I "fixed" it by prepending RewriteCond %{REQUEST_URI} /$ to the Main Rules block which makes the whole "set subdirectory" block useless. I'm not sure under which circumstances the condition RewriteCond %{REQUEST_URI} ^$ is true so im not sure if my "fix" breaks other setups.

@chesio
Copy link
Contributor

chesio commented Oct 8, 2020

Hi @uvoelkel,

I guess I stumbled upon the same problem with BC Cache (fork of Cachify). My solution was to add NS flag to the RewriteRule, see: chesio/bc-cache#6 It should work with Cachify as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants