2012-02-02 24 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]