简体   繁体   English

.htaccess拒绝访问特定文件? 超过一个

[英].htaccess deny access to specific files? more than one

I am able to disable access to a file with .htaccess, but I don't know how to disallow multiple files to be viewed (directly, not from includes) 我可以使用.htaccess禁用对文件的访问,但我不知道如何禁止查看多个文件(直接,不是来自包含)

They are .php so I can't disable a file type (like the only tutorials online say..) 它们是.php所以我无法禁用文件类型(就像在线的唯一教程说的那样..)

<FILES ... ? 

</FILES>

Or something.. For example "home.php, file.php , test.php" how do I disallow access to all three files with that tag? 或者其他东西..例如“home.php,file.php,test.php”如何禁止访问带有该标签的所有三个文件? or similar, help please! 或类似的,请帮忙!

If you want to exclude files based on regular expressions, you could use FilesMatch instead of Files, eg: 如果要基于正则表达式排除文件,可以使用FilesMatch而不是Files,例如:

<FilesMatch ^((home|test|file)\.php$|mysecretfolder|asecretpicture\.jpe?g)$>
...
</FilesMatch>

Looks like you have to exclude those files one by one: 看起来你必须逐个排除这些文件:

<files home.php>
Deny/Allow/Whatever
</files>
<files file.php>
...

You can use *.gif in <files> or something* , but as home.php, file.php and test.php can't really be grouped with a "*", this is probably the only way to go. 您可以在<files>something*使用*.gif ,但由于home.php,file.php和test.php实际上不能与“*”组合,这可能是唯一的方法。

since apache 2.4 自apache 2.4

<FilesMatch "\.htaccess|config\.php">

    Require all denied

</FilesMatch>

instead of 代替

<FilesMatch "\.htaccess|config\.php">

    Order allow,deny 
    Deny from all 

</FilesMatch>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM