MyBB Community Forums

Full Version: [PAID] .htaccess change file header cache control
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi


I have simple script


<?php


ob_start();

define("VISITOR", "fonts/visitor.ttf");

$image_background = imagecreatefrompng("images/background/bg.png");


$white = imagecolorallocate($image_background,255,255,255);

$id = $_GET['id'];

if($id == "1")
{
 imagettftext($image_background,7.5,0,35,10,$white,VISITOR, "Test 1");
}
elseif($id == "2")
{
 imagettftext($image_background,7.5,0,35,10,$white,VISITOR, "Test 2");
}
else
{
 imagettftext($image_background,7.5,0,35,10,$white,VISITOR, "Test");
}

header("Content-Type: image/png");
header("Expires: Sat, 1 Jan 2000 01:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");

imagepng($image_background);
imagedestroy($image_background);

ob_end_flush();
?>

and this return file header

Array
(
    [0] => HTTP/1.1 200 OK
    [1] => Server: nginx
    [2] => Date: Tue, 23 Feb 2021 18:38:27 GMT
    [3] => Content-Type: image/png
    [4] => Connection: close
    [5] => Expires: Sat, 1 Jan 2000 01:00:00 GMT
    [6] => Cache-Control: no-cache, must-revalidate
    [7] => Pragma: no-cache
    [8] => Last-Modified: Tue, 23 Feb 2021 18:38:27 GMT
    [9] => X-Nginx-Cache-Status: BYPASS
    [10] => X-Server-Powered-By: PS
)

Array
(
    [0] => HTTP/1.1 200 OK
    [Server] => nginx
    [Date] => Tue, 23 Feb 2021 18:38:27 GMT
    [Content-Type] => image/png
    [Connection] => close
    [Expires] => Sat, 1 Jan 2000 01:00:00 GMT
    [Cache-Control] => no-cache, must-revalidate
    [Pragma] => no-cache
    [Last-Modified] => Tue, 23 Feb 2021 18:38:27 GMT
    [X-Nginx-Cache-Status] => BYPASS
    [X-Server-Powered-By] => PS
)

it is ok, this is what i need = when I use link test/status.php?id=1
but when I use rewrite = I need to use link test/1.png < link work but change file header information

this is my .htaccess

RewriteEngine on
RewriteRule ([^-]*).png$ status.php?id=$1

rewrite change header information to
Array
(
    [0] => HTTP/1.1 200 OK
    [1] => Server: nginx
    [2] => Date: Tue, 23 Feb 2021 18:38:27 GMT
    [3] => Content-Type: image/png
    [4] => Connection: close
    [5] => Last-Modified: Tue, 23 Feb 2021 18:37:45 GMT
    [6] => Expires: Sat, 24 Apr 2021 18:38:27 GMT
    [7] => Cache-Control: max-age=5184000
    [8] => Pragma: public
)

Array
(
    [0] => HTTP/1.1 200 OK
    [Server] => nginx
    [Date] => Tue, 23 Feb 2021 18:38:27 GMT
    [Content-Type] => image/png
    [Connection] => close
    [Last-Modified] => Tue, 23 Feb 2021 18:37:45 GMT
    [Expires] => Sat, 24 Apr 2021 18:38:27 GMT
    [Cache-Control] => max-age=5184000
    [Pragma] => public
)

what i need to do to not change header, i dont need cache for this image


Conntact pm
Hello,
I can help you with your requirement.
You can add me on Skype for further discussion - live:.cid.baff7c7dd9471b54
Regards,
Trish
Hi,
I can assist you with your requirement.

PM SENT

Please check!
(2021-03-02, 02:23 PM)Trish L Wrote: [ -> ]Hello,
I can help you with your requirement.
You can add me on Skype for further discussion - live:.cid.baff7c7dd9471b54
Regards,
Trish
I dont use skype pm sent
(2021-03-02, 02:26 PM)garry_j Wrote: [ -> ]Hi,
I can assist you with your requirement.

PM SENT

Please check!

I dont have new pm
I sent pm to you
You're using nginx... Just change the location for caching image, it might work:
location ~* ^.+.(jpg|jpeg|gif|[^-]*\.png|ico)$ {

Or add a rule for your image mask with the directives expires epoch; and proxy_no_cache 1;
(2021-03-02, 03:42 PM)Crazycat Wrote: [ -> ]You're using nginx... Just change the location for caching image, it might work:
location ~* ^.+.(jpg|jpeg|gif|[^-]*\.png|ico)$ {

Or add a rule for your image mask with the directives expires epoch; and proxy_no_cache 1;
What you say it is black magic for me
regarding caching images, what about webp format, could it be used in the same line or another is needed?