【问题标题】:Matching part of a filename using the FilesMatch directive使用 FilesMatch 指令匹配文件名的一部分
【发布时间】:2012-08-26 14:00:11
【问题描述】:

如何使用 FilesMatch 指令匹配文件名的一部分?例如,如果我想匹配“utilitiesForCurrentPage.js”或customWithOtherCharacters.css,我将如何完成?我目前正在使用下面的指令。假设“utilitiesForCurrentPage.js”包含在文件夹中。

<Directory "/share/apache/files">
   ...
   ...
   <FilesMatch "^(custom*|utilities*)\.(css|gif|jpg|jpeg|js)$">
     Header set Cache-Control "public, max-age=1440, must-revalidate"
   </FilesMatch>
</Directory>

【问题讨论】:

    标签: apache apache2 webserver


    【解决方案1】:

    您的表达式中缺少.. = 匹配除换行符以外的任何内容):

    # need dot here -----v   and ----v
    <FilesMatch "^(custom.*|utilities.*)\.(css|gif|jpg|jpeg|js)$">
    

    【讨论】:

    • 正是我想要的。谢谢。
    • 为什么你需要转义第二个点而不是第一个?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-20
    • 1970-01-01
    • 1970-01-01
    • 2010-10-26
    • 1970-01-01
    • 2014-11-07
    相关资源
    最近更新 更多