拒绝使用 .htaccess 访问多个 .php 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11759433/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Deny access multiple .php files with .htaccess?
提问by Asim
I want to deny access to multiple PHP files in directory /all/cstl/.
我想拒绝访问目录中的多个 PHP 文件/all/cstl/。
My .htaccess is also stored in this directory.
我的 .htaccess 也存储在这个目录中。
This is my current code and it's not working.
这是我当前的代码,它不起作用。
<Files "\ (config.php|function.php|include.php)">
Order allow,deny
Deny from all
</Files>
I have tried to deny the directory and allow specific files but it denies the directory and does not allow the requested .php files. My code for this is:
我试图拒绝该目录并允许特定文件,但它拒绝该目录并且不允许请求的 .php 文件。我的代码是:
<Directory />
Order deny,allow
Deny from all
<Directory>
<Files "index.php|post.php">
Order deny,allow
Deny from all
</Files>
Please give me some example of blocking access to multiple specific files within a directory.
请给我一些阻止访问目录中多个特定文件的示例。
回答by Ricky Cook
There are several problems with the .htaccess you have there.
你在那里的 .htaccess 有几个问题。
As BSen linked in the comment above, you should use FilesMatch. Also, your regular expression is wrong.
正如上面评论中链接的BSen,您应该使用FilesMatch。另外,你的正则表达式是错误的。
The problem with the regular expression is that you have an escaped space at the start, so all files must start with a space character (followed by one of config.php, function.php etc)
正则表达式的问题在于开头有一个转义空格,因此所有文件都必须以空格字符开头(后跟 config.php、function.php 等之一)
Also a small explaination of the Order allow,deny directive: http://www.maxi-pedia.com/Order+allow+deny
也是 Order allow,deny 指令的一个小解释:http: //www.maxi-pedia.com/Order+allow+deny
Try this:
尝试这个:
<FilesMatch "config\.php|function\.php|include\.php">
Order allow,deny
Deny from all
</FilesMatch>
If you'd like to deny all but a few files, this would read as
如果你想拒绝除少数文件之外的所有文件,这将读作
Order deny,allow
Deny from all
<FilesMatch "index\.php|index\.html">
Allow from all
</FilesMatch>

