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)
我试过以下但没有成功:
但是在禁用.htaccess后,targetserver会一直发送304 =>'Not Modified',直到我手动刷新浏览器缓存.
所以我的问题是:我怎样才能使4月1日最后一天,最好是直到午夜...我怎样才能使浏览器意识到一旦笑话结束就必须重新加载原始图像?
归档时间: |
|
查看次数: |
487 次 |
最近记录: |