匹配目录中的文件,但不匹配子目录

时间:2013-01-24 05:52:22

标签: regex apache httpd.conf

我在Windows上运行Apache httpd。我想让Apache使index.html不可缓存 - 但主页index.html,没有其他index.html文件。这就是我到目前为止所做的:

<Directory "D:\path\to\root">
   <FilesMatch "index.html$">
      Header set Cache-Control "max-age=0, must-revalidate"
   </FilesMatch>
</Directory>

它有效 - 但适用于所有 index.html文件。我怎样才能将其缩小到只有一个index.html?显然,我可以在目录中使用正则表达式,但我这不起作用:

<Directory ~ "D:\\path\\to\\root">

2 个答案:

答案 0 :(得分:1)

您可以在Files指令中指定路径而不仅仅是文件名。所以我想这同样适用于FilesMatch指令。这样,您可以在与正则表达式匹配时排除从子目录中携带路径的文件。

请注意,我没有对此进行测试,但可能值得一试:

<Directory "D:\path\to\root">
    <FilesMatch "^[^\\]*index.html$">
        Header set Cache-Control "max-age=0, must-revalidate"
    </FilesMatch >
</Directory>

请注意,我也不确定您必须逃避哪个反斜杠(\)以及哪个不反斜。这种奇怪的路径符号MS-Windows内部使用确实是一个问题。不仅在处理正则表达式时: - )

答案 1 :(得分:0)

这很好用:

<Location /index.html>
   Header set Cache-Control "max-age=0, must-revalidate"
</Location>
相关问题