根据环境variables有条件地使用mod_expires

我从HTML5 Boilerplate中借用了一些mod_expires代码,它为资产到期添加了一些合理的默认值(我使用htaccessconfiguration了文件名版本转换,所以我可以在资源扩展之前添加m次,如script.123456789.js ):

 ExpiresActive on ExpiresDefault "access plus 1 month" # CSS ExpiresByType text/css "access plus 1 year" # Data interchange ExpiresByType application/json "access plus 0 seconds" ExpiresByType application/xml "access plus 0 seconds" ExpiresByType text/xml "access plus 0 seconds" # ... etc ... 

但是,我想在我的开发服务器(设置一个DEVELOPMENT=1环境variables)禁用这些。 如果设置了环境variables( Allow from env=DEVELOPMENT ),是否可以在2.4.4中有条件地禁用mod_expires (也许是ExpiresActive On ),就像使用mod_access一样?

我不知道基于环境variables值的任何简单的方法。 你可能可以用mod_rewrite找出一个方法,但是会很难看。

更简单的方法是让开发服务器为Apache设置一个命令行开关-DDEVELOPMENT ,而不是(或除了)环境variables。 然后,Apacheconfiguration变得微不足道:

 <IfDefine !DEVELOPMENT> ExpiresActive on ... </IfDefine> 

设置开关的正确位置取决于您的发行版。 在Debian和家庭中,你设置了

 export APACHE_ARGUMENTS=-DDEVELOPMENT 

在/ etc / apache2 / envvars中。 在RHEL中,你设置了

 OPTIONS=-DDEVELOPMENT 

在/ etc / sysconfig / httpd中。