首页 > 解决方案 > FilesMatch 指定路径

问题描述

<FilesMatch "\.html$">

如何在基目录中指定.html 文件?

我想

https://www.example.com/page.html

不是 https://www.example.com/directory/page.html

标签: regexapache.htaccess

解决方案


由于规则在.htaccess根目录中,从下面的讨论中可以清楚地看出,试试这个

<FilesMatch "^\.(html|php)$">
    <If "%{REQUEST_URI} =~ m#^/[^/]+\.(html|php)$#">
        (your directives)
    </If>
</FilesMatch>

请参阅https://httpd.apache.org/docs/2.4/sections.html#file-and-webhttps://httpd.apache.org/docs/2.4/mod/core.html#ifhttps:// /httpd.apache.org/docs/2.4/expr.html


推荐阅读