阻止通过URL直接下载zip、tar文件


prevent direct download of zip, tar files through URL

我有一个PHP应用程序,它的目录中有一些zip、tar文件。我最近注意到,它们可以直接通过URL下载。我该怎么阻止?我想,也许通过.htaccess

截至目前,我的.htaccess是这样的:

Options All -Indexes
IndexIgnore *
IndexIgnore *.jpg *.gif *.xls *.jpeg *.png *.php
ErrorDocument 404 /error.php
ErrorDocument 403 /error.php

为了防止访问特定文件,您可以在.htaccess 中使用指令<Files>

<Files ~ "'.zip$">
Order allow,deny
Deny from all
</Files>

自Apache1.3以来,建议使用<FilesMatch>,这允许文件名与常规表达式匹配

例如,以下代码将阻止对以.ini、.log、.sh和.zip 结尾的文件的访问

<FilesMatch "'.(ini|log|sh|zip)$">
Order Allow,Deny
Deny from all
</FilesMatch>

您是否尝试修改对该文件的权限?我认为将权限修改为600或其他什么可能会起作用

也许为时已晚,但您也可以使用这种方法

RewriteRule .*'.(zip|jpg|php|gif|js)$ - [F,NC]