简体   繁体   English

Htaccess访问/下载

[英]Htaccess access/download

Using htaccess I'm basically trying to forbid access to the page ie http://example.com , but it will still allow people to download files if they have a direct link ie http://example.com/hi.zip . 使用htaccess的我基本上是试图禁止访问页面即http://example.com ,但它仍然会允许人们下载文件,如果他们有直接的联系,即http://example.com/hi.zip

I'm using the directory directive to display the basic download page. 我正在使用directory指令来显示基本下载页面。 According to here mod_autoindex.c is used,so basically what I'm trying to do is: 根据这里使用 mod_autoindex.c ,基本上我要做的是:

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

Any advice/tips? 有什么建议/提示吗?

This should work (tested on my webserver: www.gopeter.de/test is restricted, www.gopeter.de/test/test.zip is allowed) 这应该工作(在我的网络服务器上测试: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>

Another way to restrict access to the home page or all pages except allowed files would be to add the following to the .htaccess file in the root directory of your site. 限制访问主页或除允许文件以外的所有页面的另一种方法是将以下内容添加到站点根目录中的.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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM