2013-01-10 36 views
3

我有這樣的目錄結構,我的Web服務器上:的Apache的.htaccess顯示目錄索引只認證用戶

web 
    privatedir1 
    privatedir2 
    publicdir 
     file1 
     file2 
     file3 

我想用的.htaccess文件中設置以下功能:

  • 用戶admin'(已認證)無限制地訪問所有dir(包括dir索引)
  • 其他人可以下載file1,file2,file3但無法看到publicdir的列表(索引)

可以請你描述如何用.htaccess文件實現這個功能嗎? 我知道如何允許/不允許目錄索引,但我不知道如何做到有條件(取決於用戶是否通過驗證)

非常感謝。

回答

0

我想你的答案可能在於在此URL

htaccess allow access to specific user

「你需要創建要允許與htpasswd工具的用戶數據庫/特定用戶。在那裏,在你的htaccess文件中要限制的目錄,使用:」

AuthUserFile /path/to/.htpasswd 
AuthName "Authorization Form Title" 
AuthType Basic 

#Allow any valid user 
require valid-user 

#Allow only one user with specified username 
require user username 

‘可以在網上大量的參考文獻中找到更多的信息,這是來到了第一個:http://www.apacheweek.com/features/userauth