2012-02-02 62 views
2

使用htaccess我基本上試圖禁止訪問頁面,即http://example.com,但它仍然允許人們下載文件,如果他們有直接鏈接,即http://example.com/hi.zipHtaccess訪問/下載

我正在使用directory指令來顯示基本的下載頁面。據heremod_autoindex.c被使用,所以基本上我想要做的是:

<Files mod_autoindex.c> 
    AuthType Basic 
    AuthName "Example" 
    AuthUserFile "/home/.htpasswd" 
    require valid-user 
</Files> 

任何意見/建議嗎?

回答

8

這應該工作(在我的網絡服務器進行測試:www.gopeter.de/test受到限制,www.gopeter.de/test/test.zip是允許的)

AuthType Basic 
AuthName "Restricted Directory" 
AuthUserFile /path/to/directory/.htpasswd 
require valid-user 

<FilesMatch "\.(gz|pdf|zip|rar)$" > 
    Order allow,deny 
    Allow from all 
    Satisfy any 
</FilesMatch> 
+0

權摸索出盒子:) – Icestorm 2012-02-02 21:31:43

2

限制訪問主頁或除允許文件外的所有頁面的另一種方法是將以下內容添加到網站根目錄中的.htaccess文件中。

RewriteEngine on 
RewriteBase/

#if not one of the allowed files 
RewriteCond %{REQUEST_URI} !^/(hi|file1|file2)\.zip[NC] 
#return a 403 forbidden 
RewriteRule^- [F]