mod_rewrite RewriteCond基于Last-modified? (.htaccess)
我知道我们可以轻松地将 RewriteCond 建立在任何 http request 标头上。但是我们可以检查(一些)将要发送的响应标头吗?特别是最后修改那个?
我只想在上次修改日期早于 30 分钟时重写 url,并且我试图避免每次请求该目录中的文件时将该检查委托给 php 文件的开销。
提前致谢!
I know that we can easily base a RewriteCond on any http request header. But can we check (some of) the response headers that are going to be sent? In particular, the Last-modified one?
I want to rewrite a url only when the Last-modified date is older than 30 minutes and I'm trying to avoid the overhead of delegating that check to a php file every single time a file from that directory is requested.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,那不可能。但是您可以使用 重写映射 从比 PHP 开销更少的程序,可能是 shell 脚本。
这是一个示例 bash 脚本:
重写映射的声明需要放置在您的服务器或虚拟主机配置文件中,因为程序只启动一次,然后等待输入:
然后您可以像这样使用重写映射(.htaccess例子):
No, that’s not possible. But you could use a rewrite map to get that information from a program with less overhead than PHP, maybe a shell script.
Here’s an example bash script:
The declaration of the rewrite map needs to be placed in your server or virtual host configuraion file as the program is just started once and then waits for input:
And then you can use that rewrite map like this (.htaccess example):
出站标头直到
mod_rewrite
生效很久
后才存在。mod_rewrite
中也没有内置任何文件修改时间检查功能,因此您最接近的使用方式就是创建一个 RewriteMap 外部重写程序类型,用于查明相关文件是否已被修改。如果我正确理解您的应用程序,您还可以考虑让 cron 作业删除该目录中超过 30 分钟的文件,然后在文件不存在的情况下重写。
The outbound headers do not exist until
much
later thanmod_rewrite
is acting. There also isn't any file-modification-time checking functionality built intomod_rewrite
, so the closest you'd get using it is making a RewriteMap of the External Rewriting Program variety to find out whether the file in question has been modified.If I understand your application correctly, you could also look into having a cron job delete files in that directory that are older than 30 minutes, and then rewriting on a file-nonexistence condition.
您是否考虑过使用 mod_proxy、mod_cache 和/或鱿鱼?听起来您正在尝试滚动自己的缓存......
Have you considered using mod_proxy, mod_cache, and/or squid? It sounds like you're trying to roll your own caching...