apache filesmatch指令帮助.想要包含"path/to/file"但不能正常工作

Ron*_*dog 7 php apache .htaccess

我想阻止直接url访问某些选定的目录.但是,可以在所选目录中创建一些文件,以便直接访问url.我在编写<filesmatch>部分时遇到了一些麻烦,无法访问"xml /"目录中的.php文件.我想在filesmatch指令中包含"path"的一部分,而不是为每个目录创建单独的<directorymatch>指令,我希望某些文件可用,但它不起作用......如果我删除"/xml /"并放<FilesMatch "\.(php)$">

在我的httpd.conf中,我设置了一个虚拟目录.在虚拟目录中,我添加了以下内容:

<DirectoryMatch "^/data/servers/dev.site.com/web/administrator/(includes|xml|css|javascript|stylesheet|cache|classes|acco
unt_files)">
        AddType application/x-httpd-php .php .html .htm
        Options none
        AllowOverride All
        Order Deny,Allow
        Deny from all


        #Target all files in "xml/" directory that end in ".php"
        <FilesMatch "/xml/\.(php)">
                AddType application/x-httpd-php .php
                Order Allow,Deny
                Allow from all
        </FilesMatch>

</DirectoryMatch>
Run Code Online (Sandbox Code Playgroud)

有谁知道我该怎么写这个?

谢谢您的帮助.

Mar*_*c B 11

FilesMatch完全依赖于文件名 - 它根本不会查看路径部分,因此您永远不会在FilesMatch块中的文件名中获得'/ xml /'.这就是为什么上面有DirectoryMatch的原因.匹配目录,然后匹配dirmatch中的文件名.