如何配置没有mod

编程入门 行业动态 更新时间:2024-10-18 12:19:16
本文介绍了如何配置没有mod_expires或mod_headers的Apache发送到期标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

托管我的网站的网络服务器未返回上次修改或到期的标头.我想纠正此问题,以确保我的Web内容可缓存.

The webserver hosting my website is not returning last-modified or expiry headers. I would like to rectify this to ensure my web content is cacheable.

我无权访问apache配置文件,因为该站点托管在我无法控制的共享环境中.但是,我可以通过.htaccess文件进行配置.服务器-Apache 1.3-未配置mod_expires或mod_headers,该公司将不会为我安装这些服务器.

I don't have access to the apache config files because the site is hosted on a shared environment that I have no control over. I can however make configurations via an .htaccess file. The server - apache 1.3 - is not configured with mod_expires or mod_headers and the company will not install these for me.

考虑到这些限制,我有什么选择?

With these limitations in mind, what are my options?

很抱歉,此处的帖子.我知道这个问题严格来说不是编程问题,更不是sys admin问题.当serverfault公开时,我将确保在此处直接提出这种性质的问题.

Sorry for the post here. I recognise this question is not strictly a programming question, and more a sys admin question. When serverfault is public I'll make sure I direct questions of this nature there.

推荐答案

什么样的内容?如果是静态的(HTML,图像,CSS),那么真正附加标题的唯一方法是通过前端Web服务器.我很惊讶托管公司没有启用mod_headers,尽管他们可能没有为.htaccess启用它.不缓存就使他们付出了更多的带宽和CPU(即金钱)的代价.

What sort of content? If static (HTML, images, CSS), then really the only way to attach headers is via the front-end webserver. I'm surprised the hosting company doesn't have mod_headers enabled, although they might not enable it for .htaccess. It's costing them more bandwidth and CPU (ie, money) to not cache.

如果是动态内容,则在生成页面时将具有控制权.这将取决于您的语言.这是PHP的示例(来自PHP手册,是一个糟糕的示例,因为它还应设置响应代码):

If it's dynamic content, then you'll have control when generating the page. This will depend on your language; here's an example for PHP (it's from the PHP manual, and is a bad example, as it should also set the response code):

if (!headers_sent()) { header('Location: www.example/'); exit; }

哦,还有关于设置缓存头的一件事:不要设置太长的时间,尤其是对于CSS和脚本.您可能不希望更改这些内容,但是当人们的浏览器中仍然有旧内容时,您不希望网站损坏.我建议将最大缓存设置设置在4-8小时范围内:这对于单个用户的会话或工作日来说非常有用,但不多.

Oh, and one thing about setting caching headers: don't set them for too long a duration, particularly for CSS and scripts. You may not think you want to change these, but you don't want a broken site while people still have the old content in their browsers. I would recommend maximum cache settings in the 4-8 hour range: good for a single user's session, or a work day, but not much more.

更多推荐

如何配置没有mod

本文发布于:2023-11-01 02:03:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547927.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:mod

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!