2010-08-04 84 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

相關問題