2010-08-04 60 views

回答

7
AuthGroupFile /dev/null 
AuthName "Private Area" 
AuthType Basic 
AuthUserFile .htpasswd 
require valid-user 


<Files "toon.php"> 
Allow from all 
Satisfy Any 

</Files> 

为我工作。不要'忘记配置.htpasswd文件。

+0

我喜欢这个答案。只是想补充一点,你可能需要'AllowOverride AuthConfig限制'在你的服务器配置 – 2014-09-06 10:05:40

24
Order Allow,Deny 
<FilesMatch "^toon\.php$"> 
Allow from all 
</FilesMatch> 

这可能是最有效的,你可以得到。

7
Deny From All 
<FilesMatch "^toon\.php$"> 
Allow From All 
</FilesMatch> 

为我工作...

+2

这里有一些区别[这个答案](http://stackoverflow.com/a/13938936/761202)? – AD7six 2013-07-24 16:34:41

+1

是的,我的代码更容易理解=) – 2013-10-18 08:31:17

+2

用什么方式=)-1来复制现有答案,不提供更多信息。 – AD7six 2013-10-18 08:36:53

2

如果像我一样,你正在寻找一种方式来对除了单个文件的整个网站/文件夹身份验证,你会发现,这种方法工作得很好:取自

#allows a single uri through the .htaccess password protection 
SetEnvIf Request_URI "/testing_uri$" test_uri 

AuthName "Restricted Area" 
AuthType Basic 
AuthUserFile /path/to/your/.htpasswd 
AuthGroupFile/
Require valid-user 

#Allow valid-user 
Deny from all 
Allow from env=test_uri 
Satisfy any 

例子:this site

2

添加以下规则htaccess文件在根

RewriteEngine on 


RewriteRule !toon\.php$ - [F] 

这将拒绝访问所有文件和文件夹,除了toon.php

相关问题