为什么此FilesMatch不正确匹配? [英] Why is this FilesMatch not matching correctly?

查看:80
本文介绍了为什么此FilesMatch不正确匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们一直在尝试将服务器配置为不缓存.htm文件,因为这会导致我们的分析包出现一些问题,并且如果访问者在浏览器中单击后退"按钮,则无法正确显示页面.

We have been attempting to configure our server not to cache our .htm files as it is causing a few issues with our analytics package as well as not displaying the pages correctly if the visitor hits the back button in their browser.

我们尝试通过添加以下内容来解决该问题:

We have attempted to tackle it by adding:

<FilesMatch "\.(htm)$">
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
Header set Warning "Testing"
</FilesMatch>

到我们的httd文件,但它似乎没有执行,但是,当我们将Header集移到FilesMatch之外时,它似乎可以正常执行.

to our httd file but it does not appear to execute, however, when we move the Header set outside of the FilesMatch it appears to execute fine..

有人对我们要去哪里有任何想法吗?

Anyone have any ideas where we are going wrong?

推荐答案

我最近需要找出同样的问题,尽管这篇文章向我指出了正确的方向,但我还是想分享一些澄清的信息来说明这一点.将来会搜索此主题的人.

I recently needed to figure out the same kind of problem and, although this post pointed me in the right direction, I wanted to share some clarifying information for the edification of those who search on this topic in the future.

David,您最初的FilesMatch无法正常工作,因为FilesMatch仅适用于文件系统上存在的真实物理文件. http://httpd.apache.org/docs/current/sections.html 声明为:

David, your initial FilesMatch was not working because FilesMatch only works on real, physical files that exist on your filesystem. http://httpd.apache.org/docs/current/sections.html states it as:

目录和文件指令,以及它们的正则表达式,将指令应用于文件系统的一部分.

The Directory and Files directives, along with their regex counterparts, apply directives to parts of the filesystem.

这也是为什么您使用LocationMatch的第二篇文章解决了该问题的原因.同样来自 http://httpd.apache.org/docs/current/sections.html,它指出:

This is also why your second post using LocationMatch resolved the issue. Also from http://httpd.apache.org/docs/current/sections.html, it states:

位置指令和它的正则表达式对应的更改了网络空间中内容的配置.<SNIP>该指令与文件系统没有任何关系.例如,以下示例显示如何将特定URL映射到mod_status提供的内部Apache HTTP Server处理程序.文件系统中不需要存在称为server-status的文件.

The Location directive and its regex counterpart, on the other hand, change the configuration for content in the webspace. < SNIP > The directive need not have anything to do with the filesystem. For example, the following example shows how to map a particular URL to an internal Apache HTTP Server handler provided by mod_status. No file called server-status needs to exist in the filesystem.

<Location /server-status>
    SetHandler server-status
</Location>

Apache文档通过以下语句总结了此行为::

The Apache docs summarizes this behavior with the following statement:

使用位置将指令应用于位于文件系统外部的内容.对于文件系统中的内容,请使用目录和文件.例外是<位置/>,这是一种简单的方法将配置应用于整个服务器.

Use Location to apply directives to content that lives outside the filesystem. For content that lives in the filesystem, use Directory and Files. An exception is < Location / >, which is an easy way to apply a configuration to the entire server.


对于那些想了解更多机械原理的人,这就是我对内部原理的理解:


For those that want to understand more of the mechanics, this is how I understand the internals:

  • 位置指令根据HTTP请求进行匹配 URI (例如,example.com/此/is/a/uri.htm ,其中没有example.com部分).
  • 另一方面,
  • Directory和Files指令根据
  • Location directives match based on the HTTP request URI (e.g. example.com/this/is/a/uri.htm without the example.com part).
  • Directory and Files directives, on the other hand, match based on whether there is a directory path or file in the filesystem of the DocumentRoot that matches to respective part of the the HTTP request URI

Apache文档将该行为总结为:

使用时间

实际上,在文件系统容器和Webspace容器之间进行选择非常容易.将指令应用于驻留在文件系统中的对象时,请始终使用目录或文件.将指令应用于不在文件系统中的对象(例如从数据库生成的网页)时,请使用位置.

[重要!]在尝试限制对文件系统中对象的访问时,切勿使用位置,这一点很重要.这是因为许多不同的网站空间位置(URL)可以映射到同一文件系统位置,从而可以规避您的限制.

What to use When

Choosing between filesystem containers and webspace containers is actually quite easy. When applying directives to objects that reside in the filesystem always use Directory or Files. When applying directives to objects that do not reside in the filesystem (such as a webpage generated from a database), use Location.

[IMPORTANT!] It is important to never use Location when trying to restrict access to objects in the filesystem. This is because many different webspace locations (URLs) could map to the same filesystem location, allowing your restrictions to be circumvented.

这篇关于为什么此FilesMatch不正确匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆