简体   繁体   English

您是否需要Apache中的mod_expires才能使用.htaccess进行浏览器缓存?

[英]Do you need mod_expires in Apache for Browser caching with .htaccess?

I'm already over 3 hours of searching for a working browser caching functionality. 我已经花了3个多小时来寻找有效的浏览器缓存功能。 I've tried over 20 HTaccess scripts, half of them resulting in a 500-error. 我尝试了20多个HTaccess脚本,其中一半导致500错误。 Yet, via PageSpeed and GTMetrix, they still shout I should use browser caching, which means the HTaccess rules are ignored or not working. 但是,通过PageSpeed和GTMetrix,他们仍然高喊我应该使用浏览器缓存,这意味着HTaccess规则将被忽略或不起作用。

By saying I've tried over 20 scripts, I think I can say at least one of them is working, but Since Google and GTMetrix say there was no browser caching, the script in .htaccess is ignored. 通过说我已经尝试了20多个脚本,我想可以说至少其中一个正在运行,但是由于Google和GTMetrix表示没有浏览器缓存,因此.htaccess中的脚本将被忽略。

So I'm really wondering what could be it. 所以我真的很想知道这可能是什么。 It might be a server related problem? 可能是服务器相关的问题? I'm running Ubuntu 12.04 我正在运行Ubuntu 12.04

Perhaps a specific php mod isn't loaded. 也许未加载特定的php mod。 Since in the code you always write <ifModule mod_expires.c> I thought, perhaps I needed the mod_expires. 由于在代码中您总是写<ifModule mod_expires.c>我想,也许我需要mod_expires。 So I created a php file with the following code 所以我用以下代码创建了一个php文件

<?php
    print_r(apache_get_modules());
?>

To see if mod_expires was enabled.. but it isn't. 查看是否启用了mod_expires ..却没有。 Exactly 24 mods were enabled, but not expires. 确实启用了24个mod,但这些过期均未过期。

For those interested, these are the mods that are enabled, printed via the above script 对于那些感兴趣的人,这些是启用的mod,通过上面的脚本打印

Array ( [0] => core [1] =>
mod_log_config [2] =>
mod_logio [3] =>
prefork [4] =>
http_core [5] => 
mod_so [6] => 
mod_alias [7] => 
mod_auth_basic [8] => 
mod_authn_file [9] => 
mod_authz_default [10] => 
mod_authz_groupfile [11] => 
mod_authz_host [12] => 
mod_authz_user [13] => 
mod_autoindex [14] => 
mod_cgi [15] => 
mod_deflate [16] => 
mod_dir [17] => 
mod_env [18] => 
mod_mime [19] => 
mod_negotiation [20] => 
mod_php5 [21] => 
mod_reqtimeout [22] => 
mod_rewrite [23] => 
mod_setenvif [24] => mod_status )

Who can tell me if mod_expires is a must have for browser caching via .htaccess and how to get it working? 谁能告诉我mod_expires是否是通过.htaccess进行浏览器缓存的必备条件,以及如何使其正常工作?

Thanks! 谢谢!

To answer my own question: 要回答我自己的问题:

If you find yourself in a problem that all the htaccess scripts aren't working, try the above PHP code (3 lines) and find out if mod_expires is active on your server. 如果您发现所有htaccess脚本均无法正常工作,请尝试上述PHP代码(3行),并确定mod_expires是否在服务器上处于活动状态。

If not: Check this tutorial how to enable it! 如果没有,请检查本教程的启用方法! :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM