在htaccess文件标签中处理多个文件

12

我如何在htaccess文件标签中添加多个文件?下面的代码适用于一个文件。

<Files wp-login.php>
Order Deny,Allow
Allow from 191.211.9.1
Deny from all
</Files>
我最终使用了这个:
<filesMatch "^(wp-login|wp-file)\.php$">
Order Deny,Allow
Allow from 190.190.0.1
Deny from all
</filesMatch>

2
使用FilesMatch代替:http://httpd.apache.org/docs/current/mod/core.html#filesmatch - LazyOne
谢谢。那让我朝着正确的方向前进了。 - Alqin
2个回答

14

尝试像这样做(未经测试但应该可行):

<Files ~ "^(admin|wp-login|one-more-file)\.php$">

或者这个:

<FilesMatch "^(admin|wp-login|one-more-file)\.php$">

谢谢你的回答,它是解决我的问题的起点。 - Alqin
1
@Alqin,你能在评论或回答中分享你的解决方案吗? - YakovL
这对我有用: <Files ~ (filename1|filename2).pdf> Header set X-Robots-Tag "noindex, nofollow" </Files> - Yvon Huynh
仅供参考,在某些共享主机上,较低的托管层可能没有启用FilesMatch,因此必须使用Files。 - Moseleyi

2

2023解决方案

以下是一些可行的选择:

向用户返回"Forbidden"

在这种情况下,"用户"/"黑客"/"对手"/"渗透测试人员"会发现这些文件存在于您的服务器上,但他/她无法访问它们!

<FilesMatch "(?:readme|license|changelog|-config|-sample)\.(?:php|md|txt|html?)">
      Require all denied
</FilesMatch>

向用户返回"404"

在这种情况下,"用户"/"黑客"/"对手"/"渗透测试者"理论上会认为这些文件根本不存在于您的服务器上!

<FilesMatch "(?:readme|license|changelog|-config|-sample)\.(?:php|md|txt|html?)">
      Redirect 404
</FilesMatch>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接