• Resolved manjana

    (@manjana)


    Hello ,

    I’ve a problem with caching 301 redirection response.

    Everything is working fine with W3TC deactivated. Everything is working OK for logged in users (“Don’t cache pages for logged in users” is checked).

    I’ve tried to exclude pages, .php files, .js files and still haven’t solved this for a week.

    I’ve a page with images that are linked to the different quizes (using “Gallery Custom Links”). Click on a link open a new page with the quiz. In a cache I see two rows for quiz page.

    Here are the rows with W3TC deactivated.

    …./kviz/kviz-i-nivo/crvenkapa/ 21622 bytes 1 2020-06-21 21:25:34 Expired Immediately
    …./kviz/kviz-i-nivo/crvenkapa 0 bytes 1 2020-06-21 21:25:31 Expired Immediately

    Zero bytes is redirection (“response-head: HTTP/2 301 Moved Permanently”).

    When I activate W3TC I’ve this situation:

    …./kviz/kviz-i-nivo/crvenkapa/ 16959 bytes 1 2020-06-21 21:37:03 2020-06-21 21:42:00
    …./kviz/kviz-i-nivo/crvenkapa 0 bytes 1 2020-06-21 21:37:03 2020-06-21 21:41:59

    As you can see cookies are cached for five minutes and every run of a quiz will give me the same questions.

    I was able to make some progress changing Browser Cache -> HTML & XML -> Set cache control header -> Cache Control Policy: no-cache(“max-age=0, private, no-store, no-cache, must-revalidate”)

    …./kviz/kviz-i-nivo/crvenkapa/ 16979 bytes 1 2020-06-21 21:45:21 Expired Immediately
    …./kviz/kviz-i-nivo/crvenkapa 0 bytes 1 2020-06-21 21:45:18 2020-06-21 21:50:17

    I’m still getting the same questions because of this cookie for redirection:

    request-method: GET
    request-Accept-Encoding: gzip, deflate, br
    response-head: HTTP/2 301 Moved Permanently
    date: Sun, 21 Jun 2020 19:45:18 GMT
    server: nginx/1.19.0
    content-type: text/html; charset=UTF-8
    content-length: 0
    x-powered-by: W3 Total Cache/0.13.3
    x-redirect-by: WordPress
    vary: Accept-Encoding
    location: …….
    cache-control: max-age=300

    How can I change this? I need max-age to be zero or to expire immediately.

    For the first row above (real page – 16979 bytes) I can see that changes that I’ve made in W3TC are applied:

    pragma: no-cache
    cache-control: max-age=0, private, no-store, no-cache, must-revalidate

    Best regards,

    Branislav…

    The page I need help with: [log in to see the link]

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @manjana

    Thank you for your inquiry and I am happy to assist you with this.
    Have you tried setting Cache-Control Policy: no-cache(“max-age=0, private, no-store, no-cache, must-revalidate”) in JS&CSS sub-box in Performance>Browser Cache and also in Media and other files?
    Thanks!

    Thread Starter manjana

    (@manjana)

    Thank you for your suggestion.

    I’ve tried that, but with no luck.

    When I add pages to the list of the pages that don’t need to be cached things are even worse. Both rows for the quiz url have an expiration time in five minutes.

    Pages, .js or .php are cached somewere and I don’t know where.

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello,

    Are you using a Proxy by any chance?
    POssibly some rules are not passing by the proxy cache.
    Thanks!

    Thread Starter manjana

    (@manjana)

    Hello,

    I don’t use proxy as far as I now.

    I’m on bluehost hosting. They use Varnish (or atleast I’ve found that info somewhere). I’ve tried to disable caching on hosting server but result is the same. I see on hosting server caching that page expiration time is 5 minutes. But even when I disable it doesn’t change anything on user end.

    One more thing. When I open page in Chrome I see only one row in page, 301 redirect. In Firefox I see two rows as I’ve described above.

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @manjana

    Thank you for the information. Can you please disable the Browser Cache, save all settings and purge the cache and see if the issue persists.
    Also, try disabling Page cache and do the same thing to see if the issue is still there.
    Thanks!

    Thread Starter manjana

    (@manjana)

    Hello Marko,

    I’ve tried that, but it is the same.

    I’ve found one strange thing. Even when I disable all options (Page Cache, Minify, Browser Cache, …), delete cache and even disable and clear server cache on hosting server pages still have max-age for 300 seconds (when I check in Firefox cache).

    On the Performance menu I see “The plugin is currently disabled in community mode.” How is this possible?

    Only when I deactivate plugin it is working OK. So we should probably start from there.

    If we can figure that out, then I think that we can make this working changing some .php files (BrowserCache_Environment.php or even BrowserCache_Environment_Nginx.php because I see “server: nginx/1.19.0” in cache).

    I could put max-age=0 or other cache-control options.

    Thanks.

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @manjana

    Something else is setting the rules and causing the conflict in this case. You mentioned that server-side caching was enabled so make sure to purge the server-side cache and check your Nginx.conf file for any rules other than W3 Total Cache rules for browser caching.
    Thanks!

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @manjana

    Thank you for your patience. I’ve tried tho replicate the issue but with no success.

    Even when I disable all options (Page Cache, Minify, Browser Cache, …), delete cache and even disable and clear server cache on hosting server pages still have max-age for 300 seconds

    This means that something else other than W3 Total Cache affects your Browser cache headers.
    Possibly some other plugin is adding the rule or server-side, or some custom rule in your .htaccess.
    This is causing the conflict so you need to check your .htaccess or httpd.conf file for those rules.
    Thanks!

    Thread Starter manjana

    (@manjana)

    Hello Marko,

    thank you for your effort to help me.

    You probably were not replicated the issue because I’ve deactivated W3TC. Now it is activated again.

    I’ve been struggling with this for days. And I know now that was my bad to get a 301 redirect into this issue at the beginning. I’we get rid of 301 and now I’ve only 200 responses.

    So here it is the situation now. I’m using Firefox and testing on this page https://www.bajkezadecu.com/kviz/kviz-i-nivo/crvenkapa/. Other pages still have 301 and I’ll fix that later.

    W3TC deactivated

    last fetched: 2020-06-29 17:57:34
    last modified: 2020-06-29 17:57:35
    expires: Expired Immediately
    cache-control: no-cache, must-revalidate, max-age=0

    Everything is working OK.

    I’ve run three tests.

    W3TC activated – without any changes in options

    last fetched: 2020-06-29 18:04:03
    last modified: 2020-06-29 18:04:05
    expires: 2020-06-29 18:09:03
    cache-control: max-age=300

    Browse Cache -> HTML & XML – I’ve made only this one change
    Set cache control header
    Cache Control policy: no-cache (“max-age=0, private, no-store, no-cache, must-revalidate”)

    last fetched: 2020-06-29 18:15:55
    last modified: 2020-06-29 18:15:58
    expires: 2020-06-29 18:20:55
    cache-control: max-age=300

    Last test:
    General Settings -> Page Cache: Enable
    Page Cache -> Never cache the following pages: kviz/kviz-i-nivo/crvenkapa

    last fetched: 2020-06-29 19:10:23
    last modified: 2020-06-29 19:10:25
    cache-control: max-age=300

    If I start the same quiz in five minutes I’ll get the same questions. This is wrong.

    I’ve checked the cache folder and page is not cached.

    For logged in users everything is working OK. “Don’t cache pages for logged in users” is checked. So, I’m sure that this can work beacuse it is working OK for logged in users. I just don’t know how yet.

    Something is changing cache-control.

    I’v tried with .js and .css caching also but I think that this is the real problem.

    .htaccess file only have this (beside W3TC lines):

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    I’m open for any suggestion. I’ve found some url for changing functions.php file so I can add cache-control for specific pages.

    Thanks…

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @manjana

    As I’ve stated before something else is setting the cache control. Possibly in httpd.conf.
    Can you please confirm that you also have the following in.htaccess:

    # BEGIN W3TC Page Cache core
    <IfModule mod_rewrite.c>

    If so, can you please remove:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    (make a backup of your.htaccess first) and see if that helps.
    Also, again, have you tried adding those pages to “Never cache following pages”?
    Or also you can try setting the define(‘DONOTCACHEPAGE’, true); constant for those pages templates.
    Thanks!

    Thread Starter manjana

    (@manjana)

    Hello Marko,

    I don’t have httpd.conf file on my hosting (bluehost). Or I can’t find it.

    Here is a part of .htaccess file:

    # BEGIN W3TC Page Cache core
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTPS} =on
    RewriteRule .* – [E=W3TC_SSL:_ssl]
    RewriteCond %{SERVER_PORT} =443
    RewriteRule .* – [E=W3TC_SSL:_ssl]
    RewriteCond %{HTTP:X-Forwarded-Proto} =https [NC]
    RewriteRule .* – [E=W3TC_SSL:_ssl]
    RewriteCond %{HTTP:Accept-Encoding} gzip
    RewriteRule .* – [E=W3TC_ENC:_gzip]
    RewriteCond %{HTTP_COOKIE} w3tc_preview [NC]
    RewriteRule .* – [E=W3TC_PREVIEW:_preview]
    RewriteCond %{REQUEST_METHOD} !=POST
    RewriteCond %{QUERY_STRING} =””
    RewriteCond %{HTTP_COOKIE} !(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle) [NC]
    RewriteCond %{REQUEST_URI} \/$
    RewriteCond “%{DOCUMENT_ROOT}/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_SSL}%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}” -f
    RewriteRule .* “/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_SSL}%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}” [L]
    </IfModule>
    # END W3TC Page Cache core

    I’ve tried to remove everything and stll have the same problem.

    Here is the content of .htaccess file from cached folder:

    # BEGIN W3TC Page Cache cache
    AddDefaultCharset UTF-8
    FileETag MTime Size
    <IfModule mod_mime.c>
    AddType text/html .html_gzip
    AddEncoding gzip .html_gzip
    AddType text/xml .xml_gzip
    AddEncoding gzip .xml_gzip
    </IfModule>
    <IfModule mod_setenvif.c>
    SetEnvIfNoCase Request_URI \.html_gzip$ no-gzip
    SetEnvIfNoCase Request_URI \.xml_gzip$ no-gzip
    </IfModule>
    <IfModule mod_headers.c>
    Header set Pragma “no-cache”
    Header set Cache-Control “max-age=0, private, no-store, no-cache, must-revalidate”
    </IfModule>
    # END W3TC Page Cache cache

    I’ve also tried to remove this but same result.

    I’m not sure where to put “define(‘DONOTCACHEPAGE’, true);” and how to define list of pages. I’ll take a look. If you can help me it would be a great.

    Thanks…

    Thread Starter manjana

    (@manjana)

    One more thing.

    In the page source there is at the end:

    <!–
    Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/

    Page Caching using disk: enhanced (Requested URI is rejected)

    Served from: www………com @ 2020-06-30 12:44:44 by W3 Total Cache
    –>

    Thanks…

    Thread Starter manjana

    (@manjana)

    Hi Marko,

    first of all thank you for your effort to help me. At the end, I wasn’t able to solve this using W3 TC options and .htaccess file.

    I’ve found a workaround for this.

    I’ve added this code to the end of my theme functions.php file:

    function update_header_cache() {
        
        $page_id_nocache = [1360, 1623, ....];
        
        if( is_page($page_id_nocache) ) {
            header('Pragma: no-cache');
            header('Cache-Control: max-age=0, private, no-store, no-cache, must-revalidate');
        }
        
    }
    
    add_action( 'template_redirect', 'update_header_cache' );

    I’ve even restored caching option (Cache Control policy: no-cache (“max-age=0, private, no-store, no-cache, must-revalidate”) to the default value.

    I don’t see a downside of this solution for now. Except that I mess with functions.php file of course :-). And I don’t know how to solve this problem in any other way.

    Thank you for your help.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Exclude “301 Moved Permanently” from caching’ is closed to new replies.