【问题标题】:htacces redirect if e-tag or last-modified in request header如果请求标头中的 etag 或最后修改,则 htaccess 重定向
【发布时间】:2013-02-08 09:00:32
【问题描述】:

我尝试四处寻找答案,但找不到任何我能理解的教程或文档,所以我什至不确定是否可行,但是;

如果最后修改日期或 etag 在请求标头中,我想重定向/重写 URL。比如:

RewriteEngine On 
RewriteBase /

RewriteCond # Only if the request uri is 'images/1px.gif'
RewriteCond # And if an etag or last modified date is in the req. header
RewriteRule ^(.*)$  /304-this.php [L]

请注意,即使这是可能的,如果这不是您建议的更好选择。

为了清楚起见,如果请求是针对 images/1px.gif 并且有 etag 或上次修改日期,我也只希望触发此重定向。

我的理论是,如果图像已经在浏览器缓存中,它将与 etag 或最后修改日期一起发送,在这种情况下,我希望 PHP 处理 304 响应。

谢谢大家!

【问题讨论】:

    标签: php .htaccess mod-rewrite last-modified etag


    【解决方案1】:

    您可以在RewriteCond 中使用%{HTTP:...} 来测试任何标头

    RewriteCond %{HTTP:etag} . [OR]
    RewriteCond %{HTTP:last-modified} .
    RewriteRule images/1px.gif$ /304-this.php [L]
    

    【讨论】:

      猜你喜欢
      • 2015-01-18
      • 2020-08-27
      • 2019-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多