【发布时间】:2019-03-15 16:48:44
【问题描述】:
我在 .htaccess 中创建了 RewriteRule 以仅在用户登录时返回文件:
RewriteRule ^(.*)$ ../authorize.php?file=$1 [NC]
authorize.php 看起来像这样:
<?php
session_start();
if (!isset($_SESSION["user_id"]) || $_SESSION["user_sessid"] != session_id() || $_REQUEST["token"] != $_TOKEN) {
header("HTTP/1.1 404 NOT FOUND");
} else {
$file = "public/" . $_REQUEST['file'];
$contentType = mime_content_type($file);
header("Content-type: $contentType");
header('Content-Disposition: inline;');
readfile($file);
}
以下是其中一个文件响应的标题:
HTTP/1.1 200 OK
Date: Thu, 14 Mar 2019 14:51:54 GMT
Server: Apache/2.4.25 (Debian)
X-Powered-By: PHP/7.0.33
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: max-age=3153600000
Pragma: no-cache
Content-Disposition: inline;
Keep-Alive: timeout=5, max=98
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: image/jpeg
问题是在这些更改之后浏览器并未缓存所有文件。有什么想法可能是错的吗?
到期时间:1981 年 11 月 19 日星期四 08:52:00 GMT 没有问题,如果我将其更改为以后的日期,文件仍处于未缓存状态。
【问题讨论】: