在Apache中,ETag作为核心功能处理.ETag被计算为几个值的散列.您可以FileETag在httpd.conf或.htaccess文件中使用该指令来定义要包含在散列中的值的条件行为,但正如您所指出的,您的选项仅限于:
INode - 您的文件在其服务的特定服务器上的索引节点号MTime - 提供文件的服务器的时间戳(以毫秒为单位)Size - 文件大小(以字节为单位)All - 上述所有的None - 以上都不是如果你想要真正自定义ETag生成,那么你最好不要编写Apache模块.但是,如果您需要快速而肮脏的修复,则可以通过将请求路由到PHP脚本并Etag在脚本中附加标头来生成自己的标记.路径在您的httpd.conf或.htaccess文件中可能如下所示:
RewriteCond %{REQUEST_FILENAME} \.png$ # This example looks for .png requests
RewriteRule ^(.*)$ /gentag.php?path=$1 [B] # ...and routes them to a PHP script
Run Code Online (Sandbox Code Playgroud)
PHP脚本可能如下所示:
<?
$path = $_GET['path']; // Grab the filepath from GET params
$cont = file_get_contents($path); // Get file contents to hash
$hash = crc32($cont); // Create your own ETag hash however you like
header("Etag: $hash"); // Send the custom Etag header
echo $cont; // Dump the file contents to output
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1643 次 |
| 最近记录: |