Forum Moderators: coopster

Message Too Old, No Replies

Cache control to return 200/304/404

Need help, works locally but not on server

         

tomda

8:39 am on Mar 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry, this is an old topic but I am currently trying to find a solution. Got no help from my host.

PROBLEM/SOLUTION
I don't have the mod_headers nor the mod_expires so solutions were given to use a redirect or this type of URL (http://www.example.com/images.php?image.gif) to deal with headers - See [webmasterworld.com...]

SCRIPT USED
So I wrote a script to check if-modified-since and if-none-match and compare it to $etag and $last_modified_time - See [webmasterworld.com...] (just to get an idea, code has been modified since)

STILL STUCK
Well, I am stuck because $_SERVER['HTTP_IF_MODIFIED_SINCE'] and $_SERVER['HTTP_IF_NONE_MATCH'] doesn't exist on my server! - See [webmasterworld.com...]

So this long post for a single simple question :
How to implement caching script when there is no HTTP_IF_MODIFIED_SINCE' and 'HTTP_IF_NONE_MATCH in server headers ?

Thank you

eelixduppy

2:52 pm on Mar 28, 2010 (gmt 0)



Do you have PHP installed as a module? If so, then I believe apache_request_headers [php.net] might be useful. Otherwise one of the user comments there suggested what looks to be a nice solution to this:


RewriteEngine on
RewriteRule .* - [E=HTTP_IF_MODIFIED_SINCE:%{HTTP:If-Modified-Since}]
RewriteRule .* - [E=HTTP_IF_NONE_MATCH:%{HTTP:If-None-Match}]

The headers are then available in PHP as
<?php
$_SERVER['HTTP_IF_MODIFIED_SINCE'];
$_SERVER['HTTP_IF_NONE_MATCH'];
?>

tomda

8:32 am on Mar 29, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Eelixduppy !

Currently reading the documentation. Will give a try ASAP and report back. Again thank you for posting on an almost-dead topic :)

Much appreciated !