简体   繁体   English

替代mod_expires来设置过期标头?

[英]Alternative to mod_expires for setting expiration headers?

I am using php on an Apache server. 我在Apache服务器上使用php。 I am unable to set expiration headers in .htaccess on the server that I am working on, as it is a shared server and they (the web host) will not install the mod_expires module in the apache build. 我无法在我正在处理的服务器上的.htaccess中设置过期标头,因为它是共享服务器,并且他们(Web主机)不会在apache构建中安装mod_expires模块。 I have always used the ExpiresActive On and set the default cache expiration for images, js , xml and text files within the .htaccess file. 我一直使用ExpiresActive On并为.htaccess文件中的images, jsxml和text文件设置默认缓存过期。

What are my other options? 我还有什么其他选择?

thanks. 谢谢。

You can do it with .htaccess and without mod_expires. 您可以使用.htaccess并且不使用mod_expires。

<IfModule mod_headers.c>
  <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
    Header set Expires "Wed, 15 Apr 2020 20:00:00 GMT"
    Header set Cache-Control "public"
  </FilesMatch>
</IfModule>

Somebody might come up with an Apache specific solution that works without the module, but as a last resort, if there is no other way, you could route all your traffic through PHP and output headers there. 有人可能会想出一个没有模块的Apache特定解决方案,但作为最后的手段,如果没有其他方法,您可以通过PHP路由所有流量并在那里输出标头。 But that would mean sending every resource through the PHP interpreter, and be horribly expensive. 但这意味着通过PHP解释器发送每个资源,并且非常昂贵。

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

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