愚人节烦人的浏览器缓存拒绝刷新

jip*_*pie 5 apache .htaccess redirect caching flush

我花了我的周末编程一个小愚人节的笑话,但它不能按我想要的方式工作.

我有一个基于Drupal 6的网站,我希望尽可能少地改变它.这个想法是,从/ files目录提供的所有图像都被重定向到外部网络服务器(myserver),它将图像颠倒翻转,然后将其提供给浏览器.

为了使Drupal网站(targetserver)将所有图像请求重定向到另一台服务器,我设置了一个.htaccess,如下所示:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} !^aprilFool$
RewriteRule ^(.*)$        http://myserver/aprilFool/?url=http://targetserver/files/$1 [R=302,L]
Run Code Online (Sandbox Code Playgroud)

到目前为止它很棒!当我启用所有内容时,愚人节的诡计会改变一些图像,并在客户端的浏览器中显示.

但是当我禁用.htaccess @targetserver时,我的浏览器拒绝意识到它只是一个临时的笑话而忘记了编辑过的图像:(

这是myserver/aprilFool上的Perl脚本的一个小节:

my $ua = LWP::UserAgent->new;
# Identify ourselves through the useragent, to prevent endless redirect loops
$ua->agent( 'aprilFool' );

# Load remote file
my $response = $ua->get( $url );
if ( $response->is_error ) { die "Cannot retrieve document $url\n"; }
my $imageData = $response->content;


# Determine the file's mime type, need that to determine if we want to change it or not
my $ft = File::Type->new();
my $format = $ft->mime_type( $imageData );

# If the file is an image, flip it
if ( $format =~ m/^image\// ) {
        my $image=Image::Magick->new;
        $image->BlobToImage( $imageData );
        $image->Flip();
        $imageData = $image->ImageToBlob();
}

# Send HTTP headers
print "Content-type:$format\r\n";
print "\r\n";
print $imageData;
Run Code Online (Sandbox Code Playgroud)

我试过以下但没有成功:

  1. 在脚本中添加一个额外的标题:print"Cache-Control:max-age = 36\r \n";
  2. 在.htaccess @targetserver中添加一行:Header set Expires"Mon Mar 12 15:45:00 CET 2012"
  3. 通过更改.htaccess @myserver中的RewriteRule,以各种方式更改image.jpg的名称tmp-image.jpg,image.jpg.tmp

但是在禁用.htaccess后,targetserver会一直发送304 =>'Not Modified',直到我手动刷新浏览器缓存.

所以我的问题是:我怎样才能使4月1日最后一天,最好是直到午夜...我怎样才能使浏览器意识到一旦笑话结束就必须重新加载原始图像?

jip*_*pie 0

结果发现是浏览器的问题。关闭选项卡,重新打开一个新选项卡会刷新旧图像。