2011-03-09 176 views
0

如何拒绝从外部访问一个文件?拒绝访问文件

if you go www.mysite.com/file.txt - ban. 
if you go /home/public_html/file.txt - ok. 

感谢;)

+1

难道你不能把它放在文档根目录之外吗? – alexn 2011-03-09 13:21:27

+0

'.exe'文件永远不会在浏览器中打开 – diEcho 2011-03-09 13:22:36

+0

对不起,txt文件:) – lolalola 2011-03-09 13:23:19

回答

2

阅读本htaccess tricksthis one

特定文件

<Files file.txt> 
    order allow,deny 
    deny from all 
</Files> 

所有扩展(.txt

<Files ~ "\.txt$"> 
Order allow,deny 
Deny from all 
</Files> 
2

假设您使用的是Apache,您可以使用.htaccess文件来限制某些文件类型。

<FilesMatch "\.txt$"> 
    Order Allow,Deny 
    Deny from all 
</FilesMatch>