That’s a problem. I see you set it to 31536000 in .htaccess, so I’m not sure where it’s getting changed.
You shouldn’t need the Cache Everything rule for static content. How about changing Browser Cache Expiration to an actual value instead of Respect Existing Headers?
HTTP/1.1 200 OK
Date: Wed, 10 Jul 2019 00:06:40 GMT
Server: Apache
Last-Modified: Wed, 03 Oct 2018 18:42:17 GMT
Accept-Ranges: bytes
Content-Length: 3374
Cache-Control: max-age=31536000, public
Content-Type: image/jpeg
It is interesting that you suggested this. I had a problem with Cloudflare back in April (my website did not show and instead got a cpanel page, /cgi-sys/defaultwebpage.cgi, suggesting “The IP address has changed.”, “There has been a server misconfiguration” or “The site may have moved to a different server.”). I investigated myself and found that the IP address quoted on cpanel was different to when I pinged it. I contacted my hosting provider and they suggested to pause Cloudflare. It worked. Then recently I unpaused Cloudflare, the website worked, but no cache. I asked them to help with the cache problem, but they said contact Cloudflare.
The response to curl above is from the IP quoted on cpanel.
Something is definitely changing it in Cloudflare. No telling which setting is affecting this cache. It could be in the Caching tab, a Page Rule, or a Worker. Or some other unknown source. Open a Support Ticket. Maybe they can track down what’s changing it. Include a link to this thread.
Thanks @sdayman for your help. The problem is finally solved.
It all came down to my hosting provider installing Imunify360 web firewall system. I overcame the problem with some page rules.
I confess I’m completely unfamiliar with that feature, and the docs don’t clear it up for me. At face value, it sounds like it overrides the server’s decision on what should or should not be cached. The docs don’t clearly state “On means this will happen. Off means this will happen.”
Origin Cache-Control = ON (Cloudflare check your server headers, if set cache public- servers will cache!, if not set, Cloudflare servers do nothing to ur content about cache)
Origin Cache-Control = OFF (Cloudflare dont check your server headers about if set or not set. Servers will be forcing your content to cache)
Ok, so it sounds like ON means your server sets cache on or off. And if Cloudflare would normally cache the resource, then Cloudflare will cache it, unless your server tells Cloudflare not to.
And OFF means Cloudflare doesn’t care what your server says. If Cloudflare would normally cache it, it will. And if you tell Cloudflare “Cache Everything”, then it will.
Browser and Edge Cache TTLs also seem like they override your server’s Cache Control.
I’ll have to sit down some time to see how they all interact.
I was too focused on the cache of the images (the .js and .css also cached) that I didn’t even notice that the .php wasn’t.
I set the Origin Cache-Control = ON and now the .php caches as well. However, the response headers are different for everything.
For an image without the Origin Cache-Control I get “public, max-age=16070400”
For an image with Origin Cache-Control = ON I get “private, max-age=16070400”
The max-age is dependent on what I set for the Browser Cache.
Having “Header set Cache-Control “max-age=31536000, public”” in my .htacess seems to make no difference at all.
Anyway, my pages are loading way quicker now. Thanks for everyone’s help.