简体   繁体   English

在某些情况下,拒绝访问htaccess中的文件

[英]Deny access to file in htaccess, on certain conditions

I can successfully block access to a file in htaccess with this: 我可以使用以下命令成功阻止对htaccess中文件的访问:

<Files "image1.jpg">  
Order Allow,Deny
Deny from all
</Files>

It works for one file, but I want to block access to thousands of files based on a pattern. 它适用于一个文件,但是我想基于一种模式来阻止对数千个文件的访问。

So something like this: 所以像这样:

<Files "source_*">  
Order Allow,Deny
Deny from all
</Files>

Note the * wildcard. 请注意*通配符。 If a file name starts with "source_" then it should deny access. 如果文件名以“ source_”开头,则它应拒绝访问。

What would that look like in the correct syntax? 用正确的语法会是什么样?

The directive you're looking for is FilesMatch . 您要查找的指令是FilesMatch With it, you can use Regex to specify files. 使用它,您可以使用Regex指定文件。 Probably something like: 大概是这样的:

<FilesMatch "source_.(gif|jpe?g|png)$">
# ...
</FilesMatch>

If you want to test your Regular Expression more easily, I'd recommend Regexr 如果您想更轻松地测试正则表达式,建议使用Regexr

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

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