FilesMatch指定路径

时间:2020-09-27 12:19:33

标签: regex apache .htaccess

<FilesMatch "\.html$">

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

我想要

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

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

1 个答案:

答案 0 :(得分:2)

由于该规则位于根目录的.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