2011-03-09 107 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>