Initial information:
- there is a redirect in the .htaccess file that causes the WebP file (image-test.png.webp) to load instead of the PNG file (image-test.png) when the browser supports the WebP format
- performs 3 requests using cURL function in PHP (source code is in index.php file)
- each request is to the same URL but contains a different Accept header
- please read carefully the descriptions of each of the 3 steps below
Request #1: should return a WebP file:
- the URL of the loaded file is: newslabturkey.org/rewrites-cached-test/image-test.png?ver=23007f
- the request contains the header: "Accept: image/webp,image/*"- this means simulating a browser that supports WebP
- in this case, the browser supports the WebP format and a WebP file with a size of 3462 bytes should be loaded
-
size of the returned file: 3462 bytes
(HTTP Response Code: 200)
Request #2: should return a PNG file:
- the URL of the loaded file is: newslabturkey.org/rewrites-cached-test/image-test.png?ver=23007f
- the request contains the header: "Accept: image/*" - this means simulating a browser that does not support WebP
- in this case, the browser does not support the WebP format and a PNG file with a size of 21586 bytes should be loaded
-
size of the returned file: 21586 bytes
(HTTP Response Code: 200)
- if the size of the returned file is the same as for the Request #1, it means that the server uses the cache for redirections from the .htaccess file
Request #3: should return a WebP file:
- the URL of the loaded file is: newslabturkey.org/rewrites-cached-test/image-test.png?ver=23007f
- the request contains the header: "Accept: image/webp,image/*"- this means simulating a browser that supports WebP
- in this case, the browser supports the WebP format and a WebP file with a size of 3462 bytes should be loaded
-
size of the returned file: 21586 bytes
(HTTP Response Code: 200)
- if the size of the returned file is the same as for the Request #2, it means that the server uses the cache for redirections from the .htaccess file
- refresh this page with the test several times - if the size of the returned file is once 3462 bytes, and once 21586 bytes, it means that the server uses the cache for redirections from the .htaccess file
Here are potential sources of this issue:
- the server or CDN server does not support the "Vary: Accept" HTTP header or handles it incorrectly (cache for redirects should not only be based on the URL to the file, but also on the value of the Accept header sent by the browser)
- the server or CDN server does not support the "Cache-Control: private" HTTP header or handles it incorrectly (this header should be able to disable cache for static files on CDN server or proxy server)