繁体   English   中英

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

[英]Match file in directory but not sub-directories

我在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中使用正则表达式,但是我没有用:

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

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

请注意,我尚未对此进行测试,但是可能值得尝试:

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

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

这很好用:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM